├── Схемы ├── RX.fzz ├── TX.fzz ├── RX_bb.jpg └── TX_bb.jpg ├── Библиотеки ├── RF24-master │ ├── examples │ │ ├── scanner │ │ │ ├── output │ │ │ │ ├── core.a │ │ │ │ ├── scanner.elf │ │ │ │ └── scanner.cpp │ │ │ ├── scanner.ino │ │ │ └── Jamfile │ │ ├── pingpair_multi_dyn │ │ │ ├── printf.h │ │ │ ├── Jamfile │ │ │ └── pingpair_multi_dyn.pde │ │ ├── Serial_Chat │ │ │ ├── printf.h │ │ │ └── nRF24_Serial_Chat.ino │ │ ├── pingpair_dyn │ │ │ ├── printf.h │ │ │ └── pingpair_dyn.ino │ │ ├── starping │ │ │ ├── printf.h │ │ │ ├── Jamfile │ │ │ └── starping.pde │ │ ├── pingpair_irq │ │ │ ├── printf.h │ │ │ ├── pingpair_irq.pde │ │ │ └── pingpair_irq.ino │ │ ├── pingpair_sleepy │ │ │ ├── printf.h │ │ │ ├── pingpair_sleepy.pde │ │ │ └── pingpair_sleepy.ino │ │ ├── Usage │ │ │ ├── pingpair_maple │ │ │ │ ├── main.cpp │ │ │ │ ├── Jamfile │ │ │ │ └── pingpair_maple.pde │ │ │ ├── nordic_fob │ │ │ │ ├── nordic_fob.pde │ │ │ │ └── Jamfile │ │ │ └── led_remote │ │ │ │ ├── Jamfile │ │ │ │ └── led_remote.pde │ │ ├── pingpair_ack │ │ │ └── pingpair_ack.ino │ │ ├── Transfer │ │ │ └── Transfer.ino │ │ ├── GettingStarted │ │ │ └── GettingStarted.ino │ │ └── TransferTimeouts │ │ │ └── TransferTimeouts.ino │ ├── keywords.txt │ ├── printf.h │ ├── nRF24L01.h │ └── RF24_config.h └── Keypad-master │ ├── README.md │ ├── library.properties │ ├── keywords.txt │ ├── examples │ ├── HelloKeypad │ │ └── HelloKeypad.ino │ ├── CustomKeypad │ │ └── CustomKeypad.ino │ ├── loopCounter │ │ └── loopCounter.ino │ ├── HelloKeypad3 │ │ └── HelloKeypad3.ino │ ├── EventKeypad │ │ └── EventKeypad.ino │ ├── MultiKey │ │ └── MultiKey.ino │ └── DynamicKeypad │ │ └── DynamicKeypad.ino │ └── src │ ├── Key.cpp │ ├── Key.h │ └── Keypad.h ├── README.md ├── Без обратной связи ├── pyroRX │ └── pyroRX.ino └── pyroTX │ └── pyroTX.ino ├── С обратной связью ├── pyroRX │ └── pyroRX.ino └── pyroTX │ └── pyroTX.ino └── С обратной связью и защитой связи ├── pyroRX └── pyroRX.ino └── pyroTX └── pyroTX.ino /Схемы/RX.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/Remote_pyro_control/HEAD/Схемы/RX.fzz -------------------------------------------------------------------------------- /Схемы/TX.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/Remote_pyro_control/HEAD/Схемы/TX.fzz -------------------------------------------------------------------------------- /Схемы/RX_bb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/Remote_pyro_control/HEAD/Схемы/RX_bb.jpg -------------------------------------------------------------------------------- /Схемы/TX_bb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/Remote_pyro_control/HEAD/Схемы/TX_bb.jpg -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/scanner/output/core.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/Remote_pyro_control/HEAD/Библиотеки/RF24-master/examples/scanner/output/core.a -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/scanner/output/scanner.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/Remote_pyro_control/HEAD/Библиотеки/RF24-master/examples/scanner/output/scanner.elf -------------------------------------------------------------------------------- /Библиотеки/Keypad-master/README.md: -------------------------------------------------------------------------------- 1 | ## Keypad library for Arduino 2 | 3 | **Authors:** *Mark Stanley***,** *Alexander Brevig* 4 | 5 | 6 | This repository is a copy of the code found here [[Arduino Playground]](http://playground.arduino.cc/Code/Keypad). 7 | 8 | The source and file structure has been modified to conform to the newer `1.5r2` library specification and is not compatible with legacy IDE's. 9 | For these IDE's, visit the link above to grab the pre `1.0` compatible version, or download it directly here: [[pre `1.0` version]](http://playground.arduino.cc/uploads/Code/keypad.zip). -------------------------------------------------------------------------------- /Библиотеки/Keypad-master/library.properties: -------------------------------------------------------------------------------- 1 | name=Keypad 2 | version=3.1.1 3 | author=Mark Stanley, Alexander Brevig 4 | maintainer=Community https://github.com/Chris--A/Keypad 5 | sentence=Keypad is a library for using matrix style keypads with the Arduino. 6 | paragraph=As of version 3.0 it now supports mulitple keypresses. This library is based upon the Keypad Tutorial. It was created to promote Hardware Abstraction. It improves readability of the code by hiding the pinMode and digitalRead calls for the user. 7 | category=Device Control 8 | url=http://playground.arduino.cc/Code/Keypad 9 | architectures=* -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/pingpair_multi_dyn/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 James Coliz, Jr. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | int serial_putc( char c, FILE * ) 20 | { 21 | Serial.write( c ); 22 | 23 | return c; 24 | } 25 | 26 | void printf_begin(void) 27 | { 28 | fdevopen( &serial_putc, 0 ); 29 | } 30 | 31 | #endif // __PRINTF_H__ 32 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/Serial_Chat/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/pingpair_dyn/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | 20 | #ifdef ARDUINO 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/keywords.txt: -------------------------------------------------------------------------------- 1 | RF24 KEYWORD1 2 | begin KEYWORD2 3 | setDataRate KEYWORD2 4 | getDataRate KEYWORD2 5 | powerUp KEYWORD2 6 | powerDown KEYWORD2 7 | whatHappened KEYWORD2 8 | writeAckPayload KEYWORD2 9 | setChannel KEYWORD2 10 | setPayloadSize KEYWORD2 11 | getPayloadSize KEYWORD2 12 | printDetails KEYWORD2 13 | startListening KEYWORD2 14 | stopListening KEYWORD2 15 | write KEYWORD2 16 | <<<<<<< HEAD 17 | startWrite KEYWORD2 18 | ======= 19 | writeFast KEYWORD2 20 | writeBlocking KEYWORD2 21 | txStandBy KEYWORD2 22 | >>>>>>> 327f0609cf7b52b70accccc175b5809dd5074704 23 | available KEYWORD2 24 | read KEYWORD2 25 | openWritingPipe KEYWORD2 26 | openReadingPipe KEYWORD2 27 | closeReadingPipe KEYWORD2 28 | enableDynamicPayloads KEYWORD2 29 | enableAckPayload KEYWORD2 30 | setAutoAck KEYWORD2 31 | setCRCLength KEYWORD2 32 | getCRCLength KEYWORD2 33 | -------------------------------------------------------------------------------- /Библиотеки/Keypad-master/keywords.txt: -------------------------------------------------------------------------------- 1 | # Keypad Library data types 2 | KeyState KEYWORD1 3 | Keypad KEYWORD1 4 | KeypadEvent KEYWORD1 5 | 6 | # Keypad Library constants 7 | NO_KEY LITERAL1 8 | IDLE LITERAL1 9 | PRESSED LITERAL1 10 | HOLD LITERAL1 11 | RELEASED LITERAL1 12 | 13 | # Keypad Library methods & functions 14 | addEventListener KEYWORD2 15 | bitMap KEYWORD2 16 | findKeyInList KEYWORD2 17 | getKey KEYWORD2 18 | getKeys KEYWORD2 19 | getState KEYWORD2 20 | holdTimer KEYWORD2 21 | isPressed KEYWORD2 22 | keyStateChanged KEYWORD2 23 | numKeys KEYWORD2 24 | pin_mode KEYWORD2 25 | pin_write KEYWORD2 26 | pin_read KEYWORD2 27 | setDebounceTime KEYWORD2 28 | setHoldTime KEYWORD2 29 | waitForKey KEYWORD2 30 | 31 | # this is a macro that converts 2d arrays to pointers 32 | makeKeymap KEYWORD2 33 | 34 | # List of objects created in the example sketches. 35 | kpd KEYWORD3 36 | keypad KEYWORD3 37 | kbrd KEYWORD3 38 | keyboard KEYWORD3 39 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #if defined (ARDUINO) && !defined (__arm__) 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #elif defined (__arm__) 34 | 35 | void printf_begin(void){} 36 | 37 | #else 38 | #error This example is only for use on Arduino. 39 | #endif // ARDUINO 40 | 41 | #endif // __PRINTF_H__ 42 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/starping/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | <<<<<<< HEAD 20 | #ifdef ARDUINO 21 | 22 | ======= 23 | >>>>>>> 828add79a5375479cd29a7433c598b8ce56ee60b 24 | int serial_putc( char c, FILE * ) 25 | { 26 | Serial.write( c ); 27 | 28 | return c; 29 | } 30 | 31 | void printf_begin(void) 32 | { 33 | fdevopen( &serial_putc, 0 ); 34 | } 35 | 36 | #else 37 | #error This example is only for use on Arduino. 38 | #endif // ARDUINO 39 | 40 | #endif // __PRINTF_H__ 41 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/pingpair_irq/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | <<<<<<< HEAD 20 | #ifdef ARDUINO 21 | ======= 22 | >>>>>>> 828add79a5375479cd29a7433c598b8ce56ee60b 23 | 24 | int serial_putc( char c, FILE * ) 25 | { 26 | Serial.write( c ); 27 | 28 | return c; 29 | } 30 | 31 | void printf_begin(void) 32 | { 33 | fdevopen( &serial_putc, 0 ); 34 | } 35 | 36 | #else 37 | #error This example is only for use on Arduino. 38 | #endif // ARDUINO 39 | 40 | #endif // __PRINTF_H__ 41 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/pingpair_sleepy/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | <<<<<<< HEAD 20 | #ifdef ARDUINO 21 | 22 | ======= 23 | >>>>>>> 828add79a5375479cd29a7433c598b8ce56ee60b 24 | int serial_putc( char c, FILE * ) 25 | { 26 | Serial.write( c ); 27 | 28 | return c; 29 | } 30 | 31 | void printf_begin(void) 32 | { 33 | fdevopen( &serial_putc, 0 ); 34 | } 35 | 36 | #else 37 | #error This example is only for use on Arduino. 38 | #endif // ARDUINO 39 | 40 | #endif // __PRINTF_H__ 41 | -------------------------------------------------------------------------------- /Библиотеки/Keypad-master/examples/HelloKeypad/HelloKeypad.ino: -------------------------------------------------------------------------------- 1 | /* @file HelloKeypad.pde 2 | || @version 1.0 3 | || @author Alexander Brevig 4 | || @contact alexanderbrevig@gmail.com 5 | || 6 | || @description 7 | || | Demonstrates the simplest use of the matrix Keypad library. 8 | || # 9 | */ 10 | #include 11 | 12 | const byte ROWS = 4; //four rows 13 | const byte COLS = 3; //three columns 14 | char keys[ROWS][COLS] = { 15 | {'1','2','3'}, 16 | {'4','5','6'}, 17 | {'7','8','9'}, 18 | {'*','0','#'} 19 | }; 20 | byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad 21 | byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad 22 | 23 | Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); 24 | 25 | void setup(){ 26 | Serial.begin(9600); 27 | } 28 | 29 | void loop(){ 30 | char key = keypad.getKey(); 31 | 32 | if (key){ 33 | Serial.println(key); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Библиотеки/Keypad-master/examples/CustomKeypad/CustomKeypad.ino: -------------------------------------------------------------------------------- 1 | /* @file CustomKeypad.pde 2 | || @version 1.0 3 | || @author Alexander Brevig 4 | || @contact alexanderbrevig@gmail.com 5 | || 6 | || @description 7 | || | Demonstrates changing the keypad size and key values. 8 | || # 9 | */ 10 | #include 11 | 12 | const byte ROWS = 4; //four rows 13 | const byte COLS = 4; //four columns 14 | //define the cymbols on the buttons of the keypads 15 | char hexaKeys[ROWS][COLS] = { 16 | {'0','1','2','3'}, 17 | {'4','5','6','7'}, 18 | {'8','9','A','B'}, 19 | {'C','D','E','F'} 20 | }; 21 | byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad 22 | byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad 23 | 24 | //initialize an instance of class NewKeypad 25 | Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 26 | 27 | void setup(){ 28 | Serial.begin(9600); 29 | } 30 | 31 | void loop(){ 32 | char customKey = customKeypad.getKey(); 33 | 34 | if (customKey){ 35 | Serial.println(customKey); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Библиотеки/Keypad-master/examples/loopCounter/loopCounter.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | const byte ROWS = 4; //four rows 5 | const byte COLS = 3; //three columns 6 | char keys[ROWS][COLS] = { 7 | {'1','2','3'}, 8 | {'4','5','6'}, 9 | {'7','8','9'}, 10 | {'*','0','#'} 11 | }; 12 | byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad 13 | byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad 14 | 15 | Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); 16 | 17 | unsigned long loopCount = 0; 18 | unsigned long timer_t = 0; 19 | 20 | void setup(){ 21 | Serial.begin(9600); 22 | 23 | // Try playing with different debounceTime settings to see how it affects 24 | // the number of times per second your loop will run. The library prevents 25 | // setting it to anything below 1 millisecond. 26 | kpd.setDebounceTime(10); // setDebounceTime(mS) 27 | } 28 | 29 | void loop(){ 30 | char key = kpd.getKey(); 31 | 32 | // Report the number of times through the loop in 1 second. This will give 33 | // you a relative idea of just how much the debounceTime has changed the 34 | // speed of your code. If you set a high debounceTime your loopCount will 35 | // look good but your keypresses will start to feel sluggish. 36 | if ((millis() - timer_t) > 1000) { 37 | Serial.print("Your loop code ran "); 38 | Serial.print(loopCount); 39 | Serial.println(" times over the last second"); 40 | loopCount = 0; 41 | timer_t = millis(); 42 | } 43 | loopCount++; 44 | if(key) 45 | Serial.println(key); 46 | } 47 | -------------------------------------------------------------------------------- /Библиотеки/Keypad-master/src/Key.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | || @file Key.cpp 3 | || @version 1.0 4 | || @author Mark Stanley 5 | || @contact mstanley@technologist.com 6 | || 7 | || @description 8 | || | Key class provides an abstract definition of a key or button 9 | || | and was initially designed to be used in conjunction with a 10 | || | state-machine. 11 | || # 12 | || 13 | || @license 14 | || | This library is free software; you can redistribute it and/or 15 | || | modify it under the terms of the GNU Lesser General Public 16 | || | License as published by the Free Software Foundation; version 17 | || | 2.1 of the License. 18 | || | 19 | || | This library is distributed in the hope that it will be useful, 20 | || | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | || | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | || | Lesser General Public License for more details. 23 | || | 24 | || | You should have received a copy of the GNU Lesser General Public 25 | || | License along with this library; if not, write to the Free Software 26 | || | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 27 | || # 28 | || 29 | */ 30 | #include 31 | 32 | 33 | // default constructor 34 | Key::Key() { 35 | kchar = NO_KEY; 36 | kstate = IDLE; 37 | stateChanged = false; 38 | } 39 | 40 | // constructor 41 | Key::Key(char userKeyChar) { 42 | kchar = userKeyChar; 43 | kcode = -1; 44 | kstate = IDLE; 45 | stateChanged = false; 46 | } 47 | 48 | 49 | void Key::key_update (char userKeyChar, KeyState userState, boolean userStatus) { 50 | kchar = userKeyChar; 51 | kstate = userState; 52 | stateChanged = userStatus; 53 | } 54 | 55 | 56 | 57 | /* 58 | || @changelog 59 | || | 1.0 2012-06-04 - Mark Stanley : Initial Release 60 | || # 61 | */ 62 | -------------------------------------------------------------------------------- /Библиотеки/Keypad-master/src/Key.h: -------------------------------------------------------------------------------- 1 | /* 2 | || 3 | || @file Key.h 4 | || @version 1.0 5 | || @author Mark Stanley 6 | || @contact mstanley@technologist.com 7 | || 8 | || @description 9 | || | Key class provides an abstract definition of a key or button 10 | || | and was initially designed to be used in conjunction with a 11 | || | state-machine. 12 | || # 13 | || 14 | || @license 15 | || | This library is free software; you can redistribute it and/or 16 | || | modify it under the terms of the GNU Lesser General Public 17 | || | License as published by the Free Software Foundation; version 18 | || | 2.1 of the License. 19 | || | 20 | || | This library is distributed in the hope that it will be useful, 21 | || | but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | || | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | || | Lesser General Public License for more details. 24 | || | 25 | || | You should have received a copy of the GNU Lesser General Public 26 | || | License along with this library; if not, write to the Free Software 27 | || | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 28 | || # 29 | || 30 | */ 31 | 32 | #ifndef Keypadlib_KEY_H_ 33 | #define Keypadlib_KEY_H_ 34 | 35 | #include 36 | 37 | #define OPEN LOW 38 | #define CLOSED HIGH 39 | 40 | typedef unsigned int uint; 41 | typedef enum{ IDLE, PRESSED, HOLD, RELEASED } KeyState; 42 | 43 | const char NO_KEY = '\0'; 44 | 45 | class Key { 46 | public: 47 | // members 48 | char kchar; 49 | int kcode; 50 | KeyState kstate; 51 | boolean stateChanged; 52 | 53 | // methods 54 | Key(); 55 | Key(char userKeyChar); 56 | void key_update(char userKeyChar, KeyState userState, boolean userStatus); 57 | 58 | private: 59 | 60 | }; 61 | 62 | #endif 63 | 64 | /* 65 | || @changelog 66 | || | 1.0 2012-06-04 - Mark Stanley : Initial Release 67 | || # 68 | */ 69 | -------------------------------------------------------------------------------- /Библиотеки/Keypad-master/examples/HelloKeypad3/HelloKeypad3.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | const byte ROWS = 2; // use 4X4 keypad for both instances 5 | const byte COLS = 2; 6 | char keys[ROWS][COLS] = { 7 | {'1','2'}, 8 | {'3','4'} 9 | }; 10 | byte rowPins[ROWS] = {5, 4}; //connect to the row pinouts of the keypad 11 | byte colPins[COLS] = {7, 6}; //connect to the column pinouts of the keypad 12 | Keypad kpd( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); 13 | 14 | 15 | const byte ROWSR = 2; 16 | const byte COLSR = 2; 17 | char keysR[ROWSR][COLSR] = { 18 | {'a','b'}, 19 | {'c','d'} 20 | }; 21 | byte rowPinsR[ROWSR] = {3, 2}; //connect to the row pinouts of the keypad 22 | byte colPinsR[COLSR] = {7, 6}; //connect to the column pinouts of the keypad 23 | Keypad kpdR( makeKeymap(keysR), rowPinsR, colPinsR, ROWSR, COLSR ); 24 | 25 | 26 | const byte ROWSUR = 4; 27 | const byte COLSUR = 1; 28 | char keysUR[ROWSUR][COLSUR] = { 29 | {'M'}, 30 | {'A'}, 31 | {'R'}, 32 | {'K'} 33 | }; 34 | // Digitran keypad, bit numbers of PCF8574 i/o port 35 | byte rowPinsUR[ROWSUR] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad 36 | byte colPinsUR[COLSUR] = {8}; //connect to the column pinouts of the keypad 37 | 38 | Keypad kpdUR( makeKeymap(keysUR), rowPinsUR, colPinsUR, ROWSUR, COLSUR ); 39 | 40 | 41 | void setup(){ 42 | // Wire.begin( ); 43 | kpdUR.begin( makeKeymap(keysUR) ); 44 | kpdR.begin( makeKeymap(keysR) ); 45 | kpd.begin( makeKeymap(keys) ); 46 | Serial.begin(9600); 47 | Serial.println( "start" ); 48 | } 49 | 50 | //byte alternate = false; 51 | char key, keyR, keyUR; 52 | void loop(){ 53 | 54 | // alternate = !alternate; 55 | key = kpd.getKey( ); 56 | keyUR = kpdUR.getKey( ); 57 | keyR = kpdR.getKey( ); 58 | 59 | if (key){ 60 | Serial.println(key); 61 | } 62 | if( keyR ) { 63 | Serial.println( keyR ); 64 | } 65 | if( keyUR ) { 66 | Serial.println( keyUR ); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/Usage/pingpair_maple/main.cpp: -------------------------------------------------------------------------------- 1 | #ifdef MAPLE_IDE 2 | 3 | #include 4 | #include "wirish.h" 5 | 6 | extern void setup(void); 7 | extern void loop(void); 8 | 9 | void board_start(const char* program_name) 10 | { 11 | // Set up the LED to steady on 12 | pinMode(BOARD_LED_PIN, OUTPUT); 13 | digitalWrite(BOARD_LED_PIN, HIGH); 14 | 15 | // Setup the button as input 16 | pinMode(BOARD_BUTTON_PIN, INPUT); 17 | digitalWrite(BOARD_BUTTON_PIN, HIGH); 18 | 19 | SerialUSB.begin(); 20 | SerialUSB.println("Press BUT"); 21 | 22 | // Wait for button press 23 | while ( !isButtonPressed() ) 24 | { 25 | } 26 | 27 | SerialUSB.println("Welcome!"); 28 | SerialUSB.println(program_name); 29 | 30 | int i = 11; 31 | while (i--) 32 | { 33 | toggleLED(); 34 | delay(50); 35 | } 36 | } 37 | 38 | /** 39 | * Custom version of _write, which will print to the USB. 40 | * In order to use it you MUST ADD __attribute__((weak)) 41 | * to _write in libmaple/syscalls.c 42 | */ 43 | extern "C" int _write (int file, char * ptr, int len) 44 | { 45 | if ( (file != 1) && (file != 2) ) 46 | return 0; 47 | else 48 | SerialUSB.write(ptr,len); 49 | return len; 50 | } 51 | 52 | /** 53 | * Re-entrant version of _write. Yagarto and Devkit now use 54 | * the re-entrant newlib, so these get called instead of the 55 | * non_r versions. 56 | */ 57 | extern "C" int _write_r (void*, int file, char * ptr, int len) 58 | { 59 | return _write( file, ptr, len); 60 | } 61 | 62 | __attribute__((constructor)) __attribute__ ((weak)) void premain() 63 | { 64 | init(); 65 | } 66 | 67 | __attribute__((weak)) void setup(void) 68 | { 69 | board_start("No program defined"); 70 | } 71 | 72 | __attribute__((weak)) void loop(void) 73 | { 74 | } 75 | 76 | __attribute__((weak)) int main(void) 77 | { 78 | setup(); 79 | 80 | while (true) 81 | { 82 | loop(); 83 | } 84 | return 0; 85 | } 86 | #endif // ifdef MAPLE_IDE 87 | // vim:cin:ai:sts=2 sw=2 ft=cpp 88 | -------------------------------------------------------------------------------- /Библиотеки/Keypad-master/examples/EventKeypad/EventKeypad.ino: -------------------------------------------------------------------------------- 1 | /* @file EventSerialKeypad.pde 2 | || @version 1.0 3 | || @author Alexander Brevig 4 | || @contact alexanderbrevig@gmail.com 5 | || 6 | || @description 7 | || | Demonstrates using the KeypadEvent. 8 | || # 9 | */ 10 | #include 11 | 12 | const byte ROWS = 4; //four rows 13 | const byte COLS = 3; //three columns 14 | char keys[ROWS][COLS] = { 15 | {'1','2','3'}, 16 | {'4','5','6'}, 17 | {'7','8','9'}, 18 | {'*','0','#'} 19 | }; 20 | 21 | byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad 22 | byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad 23 | 24 | Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); 25 | byte ledPin = 13; 26 | 27 | boolean blink = false; 28 | boolean ledPin_state; 29 | 30 | void setup(){ 31 | Serial.begin(9600); 32 | pinMode(ledPin, OUTPUT); // Sets the digital pin as output. 33 | digitalWrite(ledPin, HIGH); // Turn the LED on. 34 | ledPin_state = digitalRead(ledPin); // Store initial LED state. HIGH when LED is on. 35 | keypad.addEventListener(keypadEvent); // Add an event listener for this keypad 36 | } 37 | 38 | void loop(){ 39 | char key = keypad.getKey(); 40 | 41 | if (key) { 42 | Serial.println(key); 43 | } 44 | if (blink){ 45 | digitalWrite(ledPin,!digitalRead(ledPin)); // Change the ledPin from Hi2Lo or Lo2Hi. 46 | delay(100); 47 | } 48 | } 49 | 50 | // Taking care of some special events. 51 | void keypadEvent(KeypadEvent key){ 52 | switch (keypad.getState()){ 53 | case PRESSED: 54 | if (key == '#') { 55 | digitalWrite(ledPin,!digitalRead(ledPin)); 56 | ledPin_state = digitalRead(ledPin); // Remember LED state, lit or unlit. 57 | } 58 | break; 59 | 60 | case RELEASED: 61 | if (key == '*') { 62 | digitalWrite(ledPin,ledPin_state); // Restore LED state from before it started blinking. 63 | blink = false; 64 | } 65 | break; 66 | 67 | case HOLD: 68 | if (key == '*') { 69 | blink = true; // Blink the LED when holding the * key. 70 | } 71 | break; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Библиотеки/Keypad-master/examples/MultiKey/MultiKey.ino: -------------------------------------------------------------------------------- 1 | /* @file MultiKey.ino 2 | || @version 1.0 3 | || @author Mark Stanley 4 | || @contact mstanley@technologist.com 5 | || 6 | || @description 7 | || | The latest version, 3.0, of the keypad library supports up to 10 8 | || | active keys all being pressed at the same time. This sketch is an 9 | || | example of how you can get multiple key presses from a keypad or 10 | || | keyboard. 11 | || # 12 | */ 13 | 14 | #include 15 | 16 | const byte ROWS = 4; //four rows 17 | const byte COLS = 3; //three columns 18 | char keys[ROWS][COLS] = { 19 | {'1','2','3'}, 20 | {'4','5','6'}, 21 | {'7','8','9'}, 22 | {'*','0','#'} 23 | }; 24 | byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the kpd 25 | byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the kpd 26 | 27 | Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); 28 | 29 | unsigned long loopCount; 30 | unsigned long startTime; 31 | String msg; 32 | 33 | 34 | void setup() { 35 | Serial.begin(9600); 36 | loopCount = 0; 37 | startTime = millis(); 38 | msg = ""; 39 | } 40 | 41 | 42 | void loop() { 43 | loopCount++; 44 | if ( (millis()-startTime)>5000 ) { 45 | Serial.print("Average loops per second = "); 46 | Serial.println(loopCount/5); 47 | startTime = millis(); 48 | loopCount = 0; 49 | } 50 | 51 | // Fills kpd.key[ ] array with up-to 10 active keys. 52 | // Returns true if there are ANY active keys. 53 | if (kpd.getKeys()) 54 | { 55 | for (int i=0; i 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Channel scanner 11 | * 12 | * Example to detect interference on the various channels available. 13 | * This is a good diagnostic tool to check whether you're picking a 14 | * good channel for your application. 15 | * 16 | * Inspired by cpixip. 17 | * See http://arduino.cc/forum/index.php/topic,54795.0.html 18 | */ 19 | 20 | #include 21 | #include "nRF24L01.h" 22 | #include "RF24.h" 23 | #include "printf.h" 24 | 25 | // 26 | // Hardware configuration 27 | // 28 | 29 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 30 | 31 | RF24 radio(9,10); 32 | 33 | // 34 | // Channel info 35 | // 36 | 37 | const uint8_t num_channels = 128; 38 | uint8_t values[num_channels]; 39 | 40 | // 41 | // Setup 42 | // 43 | 44 | void setup(void) 45 | { 46 | // 47 | // Print preamble 48 | // 49 | 50 | Serial.begin(57600); 51 | printf_begin(); 52 | printf("\n\rRF24/examples/scanner/\n\r"); 53 | 54 | // 55 | // Setup and configure rf radio 56 | // 57 | 58 | radio.begin(); 59 | radio.setAutoAck(false); 60 | 61 | // Get into standby mode 62 | radio.startListening(); 63 | radio.stopListening(); 64 | 65 | // Print out header, high then low digit 66 | int i = 0; 67 | while ( i < num_channels ) 68 | { 69 | printf("%x",i>>4); 70 | ++i; 71 | } 72 | printf("\n\r"); 73 | i = 0; 74 | while ( i < num_channels ) 75 | { 76 | printf("%x",i&0xf); 77 | ++i; 78 | } 79 | printf("\n\r"); 80 | } 81 | 82 | // 83 | // Loop 84 | // 85 | 86 | const int num_reps = 100; 87 | 88 | void loop(void) 89 | { 90 | // Clear measurement values 91 | memset(values,0,sizeof(values)); 92 | 93 | // Scan all channels num_reps times 94 | int rep_counter = num_reps; 95 | while (rep_counter--) 96 | { 97 | int i = num_channels; 98 | while (i--) 99 | { 100 | // Select this channel 101 | radio.setChannel(i); 102 | 103 | // Listen for a little 104 | radio.startListening(); 105 | delayMicroseconds(225); 106 | 107 | 108 | // Did we get a carrier? 109 | if ( radio.testCarrier() ){ 110 | ++values[i]; 111 | } 112 | radio.stopListening(); 113 | } 114 | } 115 | 116 | // Print out channel measurements, clamped to a single hex digit 117 | int i = 0; 118 | while ( i < num_channels ) 119 | { 120 | printf("%x",min(0xf,values[i]&0xf)); 121 | ++i; 122 | } 123 | printf("\n\r"); 124 | } 125 | 126 | // vim:ai:cin:sts=2 sw=2 ft=cpp -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/scanner/output/scanner.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #line 1 "scanner.pde" 3 | 4 | /* 5 | Copyright (C) 2011 James Coliz, Jr. 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | version 2 as published by the Free Software Foundation. 10 | */ 11 | 12 | /** 13 | * Channel scanner 14 | * 15 | * Example to detect interference on the various channels available. 16 | * This is a good diagnostic tool to check whether you're picking a 17 | * good channel for your application. 18 | * 19 | * Inspired by cpixip. 20 | * See http://arduino.cc/forum/index.php/topic,54795.0.html 21 | */ 22 | 23 | #include 24 | #include "nRF24L01.h" 25 | #include "RF24.h" 26 | #include "printf.h" 27 | 28 | // 29 | // Hardware configuration 30 | // 31 | 32 | // Set up nRF24L01 radio on SPI bus plus pins 8 & 9 33 | 34 | RF24 radio(8,9); 35 | 36 | // 37 | // Channel info 38 | // 39 | 40 | const short num_channels = 128; 41 | short values[num_channels]; 42 | 43 | // 44 | // Setup 45 | // 46 | 47 | void setup(void) 48 | { 49 | // 50 | // Print preamble 51 | // 52 | 53 | Serial.begin(57600); 54 | printf_begin(); 55 | printf("\n\rRF24/examples/scanner/\n\r"); 56 | 57 | // 58 | // Setup and configure rf radio 59 | // 60 | 61 | radio.begin(); 62 | radio.setAutoAck(false); 63 | 64 | // Get into standby mode 65 | radio.startListening(); 66 | radio.stopListening(); 67 | 68 | // Print out header, high then low digit 69 | int i = 0; 70 | while ( i < num_channels ) 71 | { 72 | printf("%x",i>>4); 73 | ++i; 74 | } 75 | printf("\n\r"); 76 | i = 0; 77 | while ( i < num_channels ) 78 | { 79 | printf("%x",i&0xf); 80 | ++i; 81 | } 82 | printf("\n\r"); 83 | } 84 | 85 | // 86 | // Loop 87 | // 88 | 89 | const short num_reps = 100; 90 | 91 | void loop(void) 92 | { 93 | // Clear measurement values 94 | memset(values,0,num_channels); 95 | 96 | // Scan all channels num_reps times 97 | int rep_counter = num_reps; 98 | while (rep_counter--) 99 | { 100 | int i = num_channels; 101 | while (i--) 102 | { 103 | // Select this channel 104 | radio.setChannel(i); 105 | 106 | // Listen for a little 107 | radio.startListening(); 108 | delayMicroseconds(128); 109 | radio.stopListening(); 110 | 111 | // Did we get a carrier? 112 | if ( radio.testCarrier() ) 113 | ++values[i]; 114 | } 115 | } 116 | 117 | // Print out channel measurements, clamped to a single hex digit 118 | int i = 0; 119 | while ( i < num_channels ) 120 | { 121 | printf("%x",min(0xf,values[i]&0xf)); 122 | ++i; 123 | } 124 | printf("\n\r"); 125 | } 126 | 127 | 128 | // vim:ai:cin:sts=2 sw=2 ft=cpp 129 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/Usage/nordic_fob/nordic_fob.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example Nordic FOB Receiver 11 | * 12 | * This is an example of how to use the RF24 class to receive signals from the 13 | * Sparkfun Nordic FOB. Thanks to Kirk Mower for providing test hardware. 14 | * 15 | * See blog post at http://maniacbug.wordpress.com/2012/01/08/nordic-fob/ 16 | */ 17 | 18 | #include 19 | #include 20 | #include "nRF24L01.h" 21 | #include "printf.h" 22 | 23 | // 24 | // Hardware configuration 25 | // 26 | 27 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 28 | 29 | RF24 radio(9,10); 30 | 31 | // 32 | // Payload 33 | // 34 | 35 | struct payload_t 36 | { 37 | uint8_t buttons; 38 | uint16_t id; 39 | uint8_t empty; 40 | }; 41 | 42 | const char* button_names[] = { "Up", "Down", "Left", "Right", "Center" }; 43 | const int num_buttons = 5; 44 | 45 | // 46 | // Forward declarations 47 | // 48 | 49 | uint16_t flip_endian(uint16_t in); 50 | 51 | // 52 | // Setup 53 | // 54 | 55 | void setup(void) 56 | { 57 | // 58 | // Print preamble 59 | // 60 | 61 | Serial.begin(57600); 62 | printf_begin(); 63 | printf("\r\nRF24/examples/nordic_fob/\r\n"); 64 | 65 | // 66 | // Setup and configure rf radio according to the built-in parameters 67 | // of the FOB. 68 | // 69 | 70 | radio.begin(); 71 | radio.setChannel(2); 72 | radio.setPayloadSize(4); 73 | radio.setAutoAck(false); 74 | radio.setCRCLength(RF24_CRC_8); 75 | radio.openReadingPipe(1,0xE7E7E7E7E7LL); 76 | 77 | // 78 | // Start listening 79 | // 80 | 81 | radio.startListening(); 82 | 83 | // 84 | // Dump the configuration of the rf unit for debugging 85 | // 86 | 87 | radio.printDetails(); 88 | } 89 | 90 | // 91 | // Loop 92 | // 93 | 94 | void loop(void) 95 | { 96 | // 97 | // Receive each packet, dump it out 98 | // 99 | 100 | // if there is data ready 101 | if ( radio.available() ) 102 | { 103 | // Get the packet from the radio 104 | payload_t payload; 105 | radio.read( &payload, sizeof(payload) ); 106 | 107 | // Print the ID of this message. Note that the message 108 | // is sent 'big-endian', so we have to flip it. 109 | printf("#%05u Buttons ",flip_endian(payload.id)); 110 | 111 | // Print the name of each button 112 | int i = num_buttons; 113 | while (i--) 114 | { 115 | if ( ! ( payload.buttons & _BV(i) ) ) 116 | { 117 | printf("%s ",button_names[i]); 118 | } 119 | } 120 | 121 | // If no buttons, print None 122 | if ( payload.buttons == _BV(num_buttons) - 1 ) 123 | printf("None"); 124 | 125 | printf("\r\n"); 126 | } 127 | } 128 | 129 | // 130 | // Helper functions 131 | // 132 | 133 | // Change a big-endian word into a little-endian 134 | uint16_t flip_endian(uint16_t in) 135 | { 136 | uint16_t low = in >> 8; 137 | uint16_t high = in << 8; 138 | 139 | return high | low; 140 | } 141 | 142 | // vim:cin:ai:sts=2 sw=2 ft=cpp 143 | -------------------------------------------------------------------------------- /Без обратной связи/pyroRX/pyroRX.ino: -------------------------------------------------------------------------------- 1 | /* Данный скетч делает следующее: передатчик (TX) отправляет массив 2 | данных, который генерируется согласно показаниям с кнопки и с 3 | двух потенциомтеров. Приёмник (RX) получает массив, и записывает 4 | данные на реле, сервомашинку и генерирует ШИМ сигнал на транзистор. 5 | by AlexGyver 2016 6 | */ 7 | 8 | #include 9 | #include "nRF24L01.h" 10 | #include "RF24.h" 11 | 12 | float my_vcc_const = 1.1; // начальное значение константы должно быть 1.1 13 | 14 | byte MOSFET[10] = {18, 4, 5, 6, 7, 8, 14, 15, 16, 17}; //массив пинов, к которым подключены мосфеты 15 | boolean FLAGS[10]; // массив, хранящий время для таймера каждого мосфета? по умолчанию {0,0,0,0,0,0,0,0} 16 | unsigned long TIMES[10]; // массив, хранящий состояния мосфетов 17 | 18 | int fuse_time = 1500; // время в миллисекундах, которое ток будет подаваться на спираль 19 | 20 | RF24 radio(9, 10); // "создать" модуль на пинах 9 и 10 Для Уно 21 | //RF24 radio(9,53); // для Меги 22 | 23 | byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"}; //возможные номера труб 24 | 25 | void setup() { 26 | Serial.begin(9600); //открываем порт для связи с ПК 27 | 28 | // настраиваем пины мосфетов как выходы по массиву 29 | for (int i = 0; i <= 9; i++) { 30 | pinMode(MOSFET[i], OUTPUT); 31 | } 32 | 33 | radio.begin(); //активировать модуль 34 | radio.setAutoAck(1); //режим подтверждения приёма, 1 вкл 0 выкл 35 | radio.setRetries(0, 15); //(время между попыткой достучаться, число попыток) 36 | radio.enableAckPayload(); //разрешить отсылку данных в ответ на входящий сигнал 37 | radio.setPayloadSize(32); //размер пакета, в байтах 38 | 39 | radio.openReadingPipe(1, address[0]); //хотим слушать трубу 0 40 | radio.setChannel(0x60); //выбираем канал (в котором нет шумов!) 41 | 42 | radio.setPALevel (RF24_PA_MAX); //уровень мощности передатчика. На выбор RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX 43 | radio.setDataRate (RF24_1MBPS); //скорость обмена. На выбор RF24_2MBPS, RF24_1MBPS, RF24_250KBPS 44 | //должна быть одинакова на приёмнике и передатчике! 45 | //при самой низкой скорости имеем самую высокую чувствительность и дальность!! 46 | 47 | radio.powerUp(); //начать работу 48 | radio.startListening(); //начинаем слушать эфир, мы приёмный модуль 49 | } 50 | 51 | void loop() { 52 | byte pipeNo, in_data; 53 | while ( radio.available(&pipeNo)) { // слушаем эфир со всех труб 54 | radio.read( &in_data, sizeof(in_data) ); // читаем входящий сигнал 55 | 56 | if (FLAGS[in_data] == 0) { 57 | FLAGS[in_data] = 1; // поднять флаг для мосфета, по входящему сигналу 58 | TIMES[in_data] = millis(); // запомнить время прихода сигнала 59 | digitalWrite(MOSFET[in_data], HIGH); // подать питание на мосфет (на запал) 60 | 61 | Serial.print("Fuse #"); Serial.print(in_data); Serial.println(" ON"); 62 | } 63 | } 64 | 65 | for (int i = 0; i <= 9; i++) { // пройтись по всем 10ти мосфетам 66 | if (millis() - TIMES[i] > fuse_time && FLAGS[i] == 1) { // если время с момента открытия мосфета > заданного 67 | FLAGS[i] = 0; // опустить флаг 68 | digitalWrite(MOSFET[i], LOW); // закрыть мосфет, погасить запал 69 | Serial.print("Fuse #"); Serial.print(i); Serial.println(" OFF"); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Без обратной связи/pyroTX/pyroTX.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Created 2017 3 | by AlexGyver 4 | AlexGyver Home Labs Inc. 5 | */ 6 | #include "Keypad.h" //библиотека клавиатуры 7 | #include // библиотека для работы с шиной SPI 8 | #include "nRF24L01.h" // библиотека радиомодуля 9 | #include "RF24.h" // ещё библиотека радиомодуля 10 | 11 | RF24 radio(9, 10); // "создать" модуль на пинах 9 и 10 Для Уно 12 | byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"}; //возможные номера труб 13 | 14 | byte redLED = 14; 15 | byte greenLED = 15; 16 | 17 | const byte ROWS = 4; //4 строки у клавиатуры 18 | const byte COLS = 3; //три столбца 19 | char keys[4][3] = { 20 | {'1', '2', '3'}, 21 | {'4', '5', '6'}, 22 | {'7', '8', '9'}, 23 | {'*', '0', '#'} 24 | }; 25 | byte rowPins[ROWS] = {8, 7, 6, 5}; //Подключены строки (4 пина) 26 | byte colPins[COLS] = {4, 3, 2}; //подключены столбцы (3 пина) 27 | Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); //создать клавиатуру 28 | boolean flag; 29 | 30 | void setup() { 31 | Serial.begin(9600); 32 | 33 | pinMode(redLED, OUTPUT); 34 | pinMode(greenLED, OUTPUT); 35 | digitalWrite(greenLED, HIGH); // зажечь зелёный светодиод 36 | 37 | radio.begin(); //активировать модуль 38 | radio.setAutoAck(1); //режим подтверждения приёма, 1 вкл 0 выкл 39 | radio.setRetries(0, 15); //(время между попыткой достучаться, число попыток) 40 | radio.enableAckPayload(); //разрешить отсылку данных в ответ на входящий сигнал 41 | radio.setPayloadSize(32); //размер пакета, в байтах 42 | 43 | radio.openWritingPipe(address[0]); //мы - труба 0, открываем канал для передачи данных 44 | radio.setChannel(0x60); //выбираем канал (в котором нет шумов!) 45 | 46 | radio.setPALevel (RF24_PA_MAX); //уровень мощности передатчика. На выбор RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX 47 | radio.setDataRate (RF24_1MBPS); //скорость обмена. На выбор RF24_2MBPS, RF24_1MBPS, RF24_250KBPS 48 | //должна быть одинакова на приёмнике и передатчике! 49 | //при самой низкой скорости имеем самую высокую чувствительность и дальность!! 50 | 51 | radio.powerUp(); //начать работу 52 | radio.stopListening(); //не слушаем радиоэфир, мы передатчик 53 | } 54 | 55 | void loop() { 56 | byte gotByte; 57 | char key = keypad.waitForKey(); // ожидать ввод с клавиатуры, принять символ 58 | int keyInt = key - '0'; // перевести символ в целочисленный тип 59 | 60 | if (keyInt >= 0 && keyInt <= 9 && flag == 1) { // если число от 0 до 9 и флаг поднят 61 | digitalWrite(greenLED, HIGH); // включить зелёный светодиод 62 | digitalWrite(redLED, LOW); // погасить красный светодиод 63 | radio.write(&keyInt, sizeof(keyInt)); // отправить цифру с клавиатуры по радио 64 | delay(10); 65 | digitalWrite(greenLED, LOW); // погасить зелёный светодиод 66 | digitalWrite(redLED, HIGH); // зажечь красный светодиод 67 | 68 | } else if (key == '*') { // если символ * 69 | flag = 1; // поднять флаг 70 | digitalWrite(redLED, HIGH); // включить красный светодиод 71 | digitalWrite(greenLED, LOW); // погасить зелёный светодиод 72 | 73 | } else if (key == '#') { // если символ № 74 | flag = 0; // опустить флаг 75 | digitalWrite(greenLED, HIGH); // зажечь зелёный светодиод 76 | digitalWrite(redLED, LOW); // погасить красный светодиод 77 | } 78 | } 79 | 80 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/nRF24L01.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2007 Stefan Engelke 3 | Portions Copyright (C) 2011 Greg Copeland 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the "Software"), to deal in the Software without 8 | restriction, including without limitation the rights to use, copy, 9 | modify, merge, publish, distribute, sublicense, and/or sell copies 10 | of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | /* Memory Map */ 27 | #define CONFIG 0x00 28 | #define EN_AA 0x01 29 | #define EN_RXADDR 0x02 30 | #define SETUP_AW 0x03 31 | #define SETUP_RETR 0x04 32 | #define RF_CH 0x05 33 | #define RF_SETUP 0x06 34 | #define STATUS 0x07 35 | #define OBSERVE_TX 0x08 36 | #define CD 0x09 37 | #define RX_ADDR_P0 0x0A 38 | #define RX_ADDR_P1 0x0B 39 | #define RX_ADDR_P2 0x0C 40 | #define RX_ADDR_P3 0x0D 41 | #define RX_ADDR_P4 0x0E 42 | #define RX_ADDR_P5 0x0F 43 | #define TX_ADDR 0x10 44 | #define RX_PW_P0 0x11 45 | #define RX_PW_P1 0x12 46 | #define RX_PW_P2 0x13 47 | #define RX_PW_P3 0x14 48 | #define RX_PW_P4 0x15 49 | #define RX_PW_P5 0x16 50 | #define FIFO_STATUS 0x17 51 | #define DYNPD 0x1C 52 | #define FEATURE 0x1D 53 | 54 | /* Bit Mnemonics */ 55 | #define MASK_RX_DR 6 56 | #define MASK_TX_DS 5 57 | #define MASK_MAX_RT 4 58 | #define EN_CRC 3 59 | #define CRCO 2 60 | #define PWR_UP 1 61 | #define PRIM_RX 0 62 | #define ENAA_P5 5 63 | #define ENAA_P4 4 64 | #define ENAA_P3 3 65 | #define ENAA_P2 2 66 | #define ENAA_P1 1 67 | #define ENAA_P0 0 68 | #define ERX_P5 5 69 | #define ERX_P4 4 70 | #define ERX_P3 3 71 | #define ERX_P2 2 72 | #define ERX_P1 1 73 | #define ERX_P0 0 74 | #define AW 0 75 | #define ARD 4 76 | #define ARC 0 77 | #define PLL_LOCK 4 78 | #define RF_DR 3 79 | #define RF_PWR 6 80 | #define RX_DR 6 81 | #define TX_DS 5 82 | #define MAX_RT 4 83 | #define RX_P_NO 1 84 | #define TX_FULL 0 85 | #define PLOS_CNT 4 86 | #define ARC_CNT 0 87 | #define TX_REUSE 6 88 | #define FIFO_FULL 5 89 | #define TX_EMPTY 4 90 | #define RX_FULL 1 91 | #define RX_EMPTY 0 92 | #define DPL_P5 5 93 | #define DPL_P4 4 94 | #define DPL_P3 3 95 | #define DPL_P2 2 96 | #define DPL_P1 1 97 | #define DPL_P0 0 98 | #define EN_DPL 2 99 | #define EN_ACK_PAY 1 100 | #define EN_DYN_ACK 0 101 | 102 | /* Instruction Mnemonics */ 103 | #define R_REGISTER 0x00 104 | #define W_REGISTER 0x20 105 | #define REGISTER_MASK 0x1F 106 | #define ACTIVATE 0x50 107 | #define R_RX_PL_WID 0x60 108 | #define R_RX_PAYLOAD 0x61 109 | #define W_TX_PAYLOAD 0xA0 110 | #define W_ACK_PAYLOAD 0xA8 111 | #define FLUSH_TX 0xE1 112 | #define FLUSH_RX 0xE2 113 | #define REUSE_TX_PL 0xE3 114 | #define NOP 0xFF 115 | 116 | /* Non-P omissions */ 117 | #define LNA_HCURR 0 118 | 119 | /* P model memory Map */ 120 | #define RPD 0x09 121 | #define W_TX_PAYLOAD_NO_ACK 0xB0 122 | 123 | /* P model bit Mnemonics */ 124 | #define RF_DR_LOW 5 125 | #define RF_DR_HIGH 3 126 | #define RF_PWR_LOW 1 127 | #define RF_PWR_HIGH 2 128 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/RF24_config.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright (C) 2011 J. Coliz 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | version 2 as published by the Free Software Foundation. 8 | 9 | Added Arduino Due support from https://github.com/mcrosson/ 10 | */ 11 | 12 | #ifndef __RF24_CONFIG_H__ 13 | #define __RF24_CONFIG_H__ 14 | 15 | #if ARDUINO < 100 16 | #include 17 | #else 18 | #include 19 | #endif 20 | 21 | #include 22 | 23 | /*** USER DEFINES: ***/ 24 | //#define FAILURE_HANDLING 25 | //#define SERIAL_DEBUG 26 | //#define MINIMAL 27 | /**********************/ 28 | 29 | // Define _BV for non-Arduino platforms and for Arduino DUE 30 | #if defined (ARDUINO) && !defined (__arm__) 31 | #include 32 | #else 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | 39 | #if defined(__arm__) || defined (CORE_TEENSY) 40 | #include 41 | #endif 42 | 43 | #if !defined(CORE_TEENSY) 44 | #define _BV(x) (1<<(x)) 45 | #if !defined(__arm__) 46 | extern HardwareSPI SPI; 47 | #endif 48 | #endif 49 | 50 | 51 | #endif 52 | 53 | 54 | #ifdef SERIAL_DEBUG 55 | #define IF_SERIAL_DEBUG(x) ({x;}) 56 | #else 57 | #define IF_SERIAL_DEBUG(x) 58 | #if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny85__) 59 | #define printf_P(...) 60 | #endif 61 | #endif 62 | 63 | // Avoid spurious warnings 64 | // Arduino DUE is arm and uses traditional PROGMEM constructs 65 | #if 1 66 | #if ! defined( NATIVE ) && defined( ARDUINO ) && ! defined(__arm__) && ! defined( CORE_TEENSY3 ) 67 | #undef PROGMEM 68 | #define PROGMEM __attribute__(( section(".progmem.data") )) 69 | #undef PSTR 70 | #define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];})) 71 | #endif 72 | #endif 73 | 74 | // Progmem is Arduino-specific 75 | // Arduino DUE is arm and does not include avr/pgmspace 76 | #if defined(ARDUINO) && ! defined(__arm__) 77 | #include 78 | #define PRIPSTR "%S" 79 | #else 80 | #if ! defined(ARDUINO) // This doesn't work on Arduino DUE 81 | typedef char const char; 82 | #else // Fill in pgm_read_byte that is used, but missing from DUE 83 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) 84 | #endif 85 | 86 | 87 | #if !defined ( CORE_TEENSY ) 88 | typedef uint16_t prog_uint16_t; 89 | #define PSTR(x) (x) 90 | #define printf_P printf 91 | #define strlen_P strlen 92 | #define PROGMEM 93 | #define pgm_read_word(p) (*(p)) 94 | #endif 95 | 96 | #define PRIPSTR "%s" 97 | 98 | #endif 99 | 100 | 101 | 102 | // ATTiny support code is from https://github.com/jscrane/RF24 103 | 104 | #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) 105 | #include 106 | #include 107 | #include 108 | 109 | #define SPI_CLOCK_DIV4 0x00 110 | #define SPI_CLOCK_DIV16 0x01 111 | #define SPI_CLOCK_DIV64 0x02 112 | #define SPI_CLOCK_DIV128 0x03 113 | #define SPI_CLOCK_DIV2 0x04 114 | #define SPI_CLOCK_DIV8 0x05 115 | #define SPI_CLOCK_DIV32 0x06 116 | //#define SPI_CLOCK_DIV64 0x07 117 | 118 | #define SPI_MODE0 0x00 119 | #define SPI_MODE1 0x04 120 | #define SPI_MODE2 0x08 121 | #define SPI_MODE3 0x0C 122 | 123 | #define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR 124 | #define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR 125 | #define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR 126 | 127 | 128 | 129 | class SPIClass { 130 | public: 131 | static byte transfer(byte _data); 132 | 133 | // SPI Configuration methods 134 | 135 | inline static void attachInterrupt(); 136 | inline static void detachInterrupt(); // Default 137 | 138 | static void begin(); // Default 139 | static void end(); 140 | 141 | static void setBitOrder(uint8_t); 142 | static void setDataMode(uint8_t); 143 | static void setClockDivider(uint8_t); 144 | }; 145 | extern SPIClass SPI; 146 | 147 | #endif //ATTiny 148 | #endif // __RF24_CONFIG_H__ 149 | 150 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/Usage/pingpair_maple/Jamfile: -------------------------------------------------------------------------------- 1 | MCU = cortex-m3 ; 2 | CHIP = STM32F103ZE ; 3 | BOARD = maple_native ; 4 | 5 | #CHIP = at91sam3u4 ; 6 | #BOARD = sam3u-ek ; 7 | 8 | if ! $(TOOLSET) 9 | { 10 | TOOLSET = devkit ; 11 | Echo "Assuming TOOLSET=devkit" ; 12 | } 13 | 14 | if $(TOOLSET) = yagarto 15 | { 16 | TOOLS_PATH = ~/Source/yagarto-4.6.2/bin ; 17 | TOOLS_ARCH = arm-none-eabi- ; 18 | } 19 | if $(TOOLSET) = yagarto-install 20 | { 21 | TOOLS_PATH = ~/Source/yagarto/install/bin ; 22 | TOOLS_ARCH = arm-none-eabi- ; 23 | } 24 | else if $(TOOLSET) = devkit 25 | { 26 | TOOLS_PATH = /opt/devkitARM/bin ; 27 | TOOLS_ARCH = arm-eabi- ; 28 | } 29 | else if $(TOOLSET) = maple 30 | { 31 | TOOLS_PATH = /opt/Maple/Resources/Java/hardware/tools/arm/bin ; 32 | TOOLS_ARCH = arm-none-eabi- ; 33 | } 34 | else if $(TOOLSET) = ports 35 | { 36 | TOOLS_PATH = /opt/local/bin ; 37 | TOOLS_ARCH = arm-none-eabi- ; 38 | } 39 | 40 | CC = $(TOOLS_PATH)/$(TOOLS_ARCH)gcc ; 41 | C++ = $(TOOLS_PATH)/$(TOOLS_ARCH)g++ ; 42 | AS = $(TOOLS_PATH)/$(TOOLS_ARCH)gcc -c ; 43 | LINK = $(TOOLS_PATH)/$(TOOLS_ARCH)g++ ; 44 | OBJCOPY = $(TOOLS_PATH)/$(TOOLS_ARCH)objcopy ; 45 | DFU = dfu-util ; 46 | 47 | DEFINES += VECT_TAB_FLASH BOARD_$(BOARD) MCU_$(CHIP) ERROR_LED_PORT=GPIOC ERROR_LED_PIN=15 STM32_HIGH_DENSITY MAPLE_IDE ; 48 | OPTIM = -Os ; 49 | MFLAGS = cpu=$(MCU) thumb arch=armv7-m ; 50 | CCFLAGS = -Wall -m$(MFLAGS) -g -nostdlib -ffunction-sections -fdata-sections -Wl,--gc-sections ; 51 | C++FLAGS = $(CCFLAGS) -fno-rtti -fno-exceptions ; 52 | LINKFLAGS += -m$(MFLAGS) -Xlinker --gc-sections ; 53 | DFUFLAGS = -a1 -d 0x1eaf:0x0003 -R ; 54 | 55 | MAPLE_DIR = $(HOME)/Source/SAM3U/libmaple ; 56 | MAPLE_LIBS = Servo LiquidCrystal Wire FreeRTOS ; 57 | MAPLE_SUBDIRS = wirish wirish/comm wirish/boards libmaple libmaple/usb libmaple/usb/usb_lib ; 58 | 59 | SKETCH_DIR = $(HOME)/Source/Arduino ; 60 | SKETCH_LIBS = RF24 ; 61 | 62 | MODULE_DIRS = . $(MAPLE_DIR)/$(MAPLE_SUBDIRS) $(MAPLE_DIR)/libraries/$(MAPLE_LIBS) $(SKETCH_DIR)/libraries/$(SKETCH_LIBS) ; 63 | HDRS = $(MODULE_DIRS) ; 64 | LOCATE_TARGET = out/$(TOOLSET) ; 65 | LOCATE_SOURCE = $(LOCATE_TARGET) ; 66 | 67 | rule Pde 68 | { 69 | Depends $(<) : $(>) ; 70 | MakeLocate $(<) : $(LOCATE_SOURCE) ; 71 | Clean clean : $(<) ; 72 | } 73 | 74 | if ( $(ARDUINO_VERSION) < 100 ) 75 | { 76 | ARDUINO_H = WProgram.h ; 77 | } 78 | else 79 | { 80 | ARDUINO_H = Arduino.h ; 81 | } 82 | 83 | actions Pde 84 | { 85 | echo "#include <$(ARDUINO_H)>" > $(<) 86 | echo "#line 1 \"$(>)\"" >> $(<) 87 | cat $(>) >> $(<) 88 | } 89 | 90 | rule C++Pde 91 | { 92 | local _CPP = $(>:B).cpp ; 93 | Pde $(_CPP) : $(>) ; 94 | C++ $(<) : $(_CPP) ; 95 | } 96 | 97 | rule Hex 98 | { 99 | Depends $(<) : $(>) ; 100 | MakeLocate $(<) : $(LOCATE_TARGET) ; 101 | Depends hex : $(<) ; 102 | Clean clean : $(<) ; 103 | } 104 | 105 | actions Hex 106 | { 107 | $(OBJCOPY) -O ihex $(>) $(<) 108 | } 109 | 110 | rule Binary 111 | { 112 | Depends $(<) : $(>) ; 113 | MakeLocate $(<) : $(LOCATE_TARGET) ; 114 | Depends binary : $(<) ; 115 | Clean clean : $(<) ; 116 | } 117 | 118 | actions Binary 119 | { 120 | $(OBJCOPY) -O binary $(>) $(<) 121 | } 122 | 123 | rule UserObject 124 | { 125 | switch $(>:S) 126 | { 127 | case .S : As $(<) : $(>) ; 128 | case .ino : C++Pde $(<) : $(>) ; 129 | case .pde : C++Pde $(<) : $(>) ; 130 | } 131 | } 132 | 133 | rule Upload 134 | { 135 | Depends up : $(<) ; 136 | NotFile up ; 137 | Always $(<) ; 138 | Always up ; 139 | } 140 | 141 | actions Upload 142 | { 143 | $(DFU) $(DFUFLAGS) -D $(<) 144 | } 145 | 146 | # Override base objects rule, so all output can go in the output dir 147 | rule Objects 148 | { 149 | local _i ; 150 | 151 | for _i in [ FGristFiles $(<) ] 152 | { 153 | local _b = $(_i:B)$(SUFOBJ) ; 154 | local _o = $(_b:G=$(SOURCE_GRIST:E)) ; 155 | Object $(_o) : $(_i) ; 156 | Depends obj : $(_o) ; 157 | } 158 | } 159 | 160 | # Override base main rule, so all output can go in the output dir 161 | rule Main 162 | { 163 | MainFromObjects $(<) : $(>:B)$(SUFOBJ) ; 164 | Objects $(>) ; 165 | } 166 | 167 | # Modules 168 | MODULES = [ GLOB $(MODULE_DIRS) : *.pde *.c *.cpp *.S ] ; 169 | 170 | # Main output executable 171 | MAIN = $(PWD:B).elf ; 172 | 173 | # Linker script 174 | LINK_DIR = $(MAPLE_DIR)/support/ld ; 175 | LINKSCRIPT = $(LINK_DIR)/$(BOARD)/flash.ld ; 176 | 177 | # Bring in the map and link script 178 | LINKFLAGS += -Wl,-Map=$(LOCATE_TARGET)/$(MAIN:B).map -T$(LINKSCRIPT) -L$(LINK_DIR) ; 179 | 180 | Main $(MAIN) : $(MODULES) ; 181 | Binary $(MAIN:B).bin : $(MAIN) ; 182 | Upload $(MAIN:B).bin ; 183 | -------------------------------------------------------------------------------- /С обратной связью/pyroRX/pyroRX.ino: -------------------------------------------------------------------------------- 1 | /* Данный скетч делает следующее: передатчик (TX) отправляет массив 2 | данных, который генерируется согласно показаниям с кнопки и с 3 | двух потенциомтеров. Приёмник (RX) получает массив, и записывает 4 | данные на реле, сервомашинку и генерирует ШИМ сигнал на транзистор. 5 | by AlexGyver 2016 6 | */ 7 | 8 | #include 9 | #include "nRF24L01.h" 10 | #include "RF24.h" 11 | 12 | float my_vcc_const = 1.1; // начальное значение константы должно быть 1.1 13 | 14 | byte MOSFET[10] = {18, 4, 5, 6, 7, 8, 14, 15, 16, 17}; //массив пинов, к которым подключены мосфеты 15 | boolean FLAGS[10]; // массив, хранящий время для таймера каждого мосфета? по умолчанию {0,0,0,0,0,0,0,0} 16 | unsigned long TIMES[10]; // массив, хранящий состояния мосфетов 17 | byte battery_pin = 6; // сюда подключен аккумулятор для измерения напряжения 18 | boolean RXstate; 19 | 20 | int fuse_time = 1500; // время в миллисекундах, которое ток будет подаваться на спираль 21 | int battery_check = 2800; // нижняя граница заряда аккумулятора для защиты, в милливольтах! 22 | 23 | RF24 radio(9, 10); // "создать" модуль на пинах 9 и 10 Для Уно 24 | //RF24 radio(9,53); // для Меги 25 | 26 | byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"}; //возможные номера труб 27 | 28 | void setup() { 29 | Serial.begin(9600); //открываем порт для связи с ПК 30 | 31 | // настраиваем пины мосфетов как выходы по массиву 32 | for (int i = 0; i <= 9; i++) { 33 | pinMode(MOSFET[i], OUTPUT); 34 | } 35 | 36 | radio.begin(); //активировать модуль 37 | radio.setAutoAck(1); //режим подтверждения приёма, 1 вкл 0 выкл 38 | radio.setRetries(0, 15); //(время между попыткой достучаться, число попыток) 39 | radio.enableAckPayload(); //разрешить отсылку данных в ответ на входящий сигнал 40 | radio.setPayloadSize(32); //размер пакета, в байтах 41 | 42 | radio.openReadingPipe(1, address[0]); //хотим слушать трубу 0 43 | radio.setChannel(0x60); //выбираем канал (в котором нет шумов!) 44 | 45 | radio.setPALevel (RF24_PA_MAX); //уровень мощности передатчика. На выбор RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX 46 | radio.setDataRate (RF24_1MBPS); //скорость обмена. На выбор RF24_2MBPS, RF24_1MBPS, RF24_250KBPS 47 | //должна быть одинакова на приёмнике и передатчике! 48 | //при самой низкой скорости имеем самую высокую чувствительность и дальность!! 49 | 50 | radio.powerUp(); //начать работу 51 | radio.startListening(); //начинаем слушать эфир, мы приёмный модуль 52 | } 53 | 54 | void loop() { 55 | byte pipeNo, in_data; 56 | while ( radio.available(&pipeNo)) { // слушаем эфир со всех труб 57 | radio.read( &in_data, sizeof(in_data) ); // читаем входящий сигнал 58 | Serial.println(in_data); 59 | 60 | if (in_data == 111) { 61 | int voltage = analogRead(battery_pin) * readVcc() / 1024; 62 | if (voltage > battery_check) RXstate = 1; else RXstate = 0; 63 | 64 | radio.writeAckPayload(pipeNo, &RXstate, sizeof(RXstate) ); 65 | Serial.println("Check state sent"); 66 | } else { 67 | if (FLAGS[in_data] == 0) { 68 | FLAGS[in_data] = 1; // поднять флаг для мосфета, по входящему сигналу 69 | TIMES[in_data] = millis(); // запомнить время прихода сигнала 70 | digitalWrite(MOSFET[in_data], HIGH); // подать питание на мосфет (на запал) 71 | 72 | Serial.print("Fuse #"); Serial.print(in_data); Serial.println(" ON"); 73 | } 74 | } 75 | } 76 | 77 | for (int i = 0; i <= 9; i++) { // пройтись по всем 10ти мосфетам 78 | if (millis() - TIMES[i] > fuse_time && FLAGS[i] == 1) { // если время с момента открытия мосфета > заданного 79 | FLAGS[i] = 0; // опустить флаг 80 | digitalWrite(MOSFET[i], LOW); // закрыть мосфет, погасить запал 81 | Serial.print("Fuse #"); Serial.print(i); Serial.println(" OFF"); 82 | } 83 | } 84 | } 85 | 86 | long readVcc() { //функция чтения внутреннего опорного напряжения, универсальная (для всех ардуин) 87 | #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) 88 | ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); 89 | #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) 90 | ADMUX = _BV(MUX5) | _BV(MUX0); 91 | #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) 92 | ADMUX = _BV(MUX3) | _BV(MUX2); 93 | #else 94 | ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); 95 | #endif 96 | delay(2); // Wait for Vref to settle 97 | ADCSRA |= _BV(ADSC); // Start conversion 98 | while (bit_is_set(ADCSRA, ADSC)); // measuring 99 | uint8_t low = ADCL; // must read ADCL first - it then locks ADCH 100 | uint8_t high = ADCH; // unlocks both 101 | long result = (high << 8) | low; 102 | 103 | result = my_vcc_const * 1023 * 1000 / result; // расчёт реального VCC 104 | return result; // возвращает VCC 105 | } 106 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/Serial_Chat/nRF24_Serial_Chat.ino: -------------------------------------------------------------------------------- 1 | /* 2 | nRF Serial Chat 3 | 4 | Date : 29 Sep 2015 5 | Author : Stanley Seow 6 | e-mail : stanleyseow@gmail.com 7 | Version : 1.00 8 | Desc : 9 | I worte this simple interactive serial chat over nRF that can be used for both sender 10 | and receiver as I swapped the TX & RX addr during read/write operation. 11 | 12 | It read input from Serial Monitor and display the output to the other side 13 | Serial Monitor or 16x2 LCD (if available)... like a simple chat program. 14 | 15 | Max payload is 32 bytes for radio but the serialEvent will chopped the entire buffer 16 | for next payload to be sent out sequentially. 17 | 18 | */ 19 | 20 | #define I2C_LCD 21 | 22 | #ifdef I2C_LCD 23 | #include 24 | #include 25 | LiquidCrystal_I2C lcd(0x3F,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display 26 | //LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display 27 | #endif 28 | 29 | #include 30 | #include "nRF24L01.h" 31 | #include "RF24.h" 32 | #include "printf.h" 33 | 34 | 35 | RF24 radio(8,9); 36 | 37 | const uint64_t pipes[2] = { 0xDEDEDEDEE7LL, 0xDEDEDEDEE9LL }; 38 | 39 | boolean stringComplete = false; // whether the string is complete 40 | static int dataBufferIndex = 0; 41 | boolean stringOverflow = false; 42 | char charOverflow = 0; 43 | 44 | char SendPayload[31] = ""; 45 | char RecvPayload[31] = ""; 46 | char serialBuffer[31] = ""; 47 | 48 | void setup(void) { 49 | 50 | Serial.begin(9600); 51 | 52 | #ifdef I2C_LCD 53 | lcd.init(); 54 | lcd.backlight(); 55 | lcd.begin(16,2); 56 | lcd.print("RF Chat V1.0"); 57 | delay(500); 58 | //lcd.clear(); 59 | #endif 60 | 61 | printf_begin(); 62 | radio.begin(); 63 | 64 | radio.setDataRate(RF24_250KBPS); 65 | radio.setPALevel(RF24_PA_MAX); 66 | radio.setChannel(70); 67 | 68 | radio.enableDynamicPayloads(); 69 | radio.setRetries(15,15); 70 | radio.setCRCLength(RF24_CRC_16); 71 | 72 | radio.openWritingPipe(pipes[0]); 73 | radio.openReadingPipe(1,pipes[1]); 74 | 75 | radio.startListening(); 76 | radio.printDetails(); 77 | 78 | Serial.println(); 79 | Serial.println("RF Chat V01.0"); 80 | delay(500); 81 | lcd.clear(); 82 | } 83 | 84 | void loop(void) { 85 | 86 | nRF_receive(); 87 | serial_receive(); 88 | 89 | } // end loop() 90 | 91 | void serialEvent() { 92 | while (Serial.available() > 0 ) { 93 | char incomingByte = Serial.read(); 94 | 95 | if (stringOverflow) { 96 | serialBuffer[dataBufferIndex++] = charOverflow; // Place saved overflow byte into buffer 97 | serialBuffer[dataBufferIndex++] = incomingByte; // saved next byte into next buffer 98 | stringOverflow = false; // turn overflow flag off 99 | } else if (dataBufferIndex > 31) { 100 | stringComplete = true; // Send this buffer out to radio 101 | stringOverflow = true; // trigger the overflow flag 102 | charOverflow = incomingByte; // Saved the overflow byte for next loop 103 | dataBufferIndex = 0; // reset the bufferindex 104 | break; 105 | } 106 | else if(incomingByte=='\n'){ 107 | serialBuffer[dataBufferIndex] = 0; 108 | stringComplete = true; 109 | } else { 110 | serialBuffer[dataBufferIndex++] = incomingByte; 111 | serialBuffer[dataBufferIndex] = 0; 112 | } 113 | } // end while() 114 | } // end serialEvent() 115 | 116 | void nRF_receive(void) { 117 | int len = 0; 118 | if ( radio.available() ) { 119 | len = radio.getDynamicPayloadSize(); 120 | radio.read(&RecvPayload,len); 121 | delay(5); 122 | 123 | RecvPayload[len] = 0; // null terminate string 124 | 125 | #ifdef I2C_LCD 126 | lcd.setCursor(0,0); 127 | lcd.print("R: "); 128 | lcd.setCursor(2,0); 129 | lcd.print(RecvPayload); 130 | #endif 131 | Serial.print("R:"); 132 | Serial.print(RecvPayload); 133 | Serial.println(); 134 | RecvPayload[0] = 0; // Clear the buffers 135 | } 136 | 137 | } // end nRF_receive() 138 | 139 | void serial_receive(void){ 140 | 141 | if (stringComplete) { 142 | strcat(SendPayload,serialBuffer); 143 | // swap TX & Rx addr for writing 144 | radio.openWritingPipe(pipes[1]); 145 | radio.openReadingPipe(0,pipes[0]); 146 | radio.stopListening(); 147 | radio.write(&SendPayload,strlen(SendPayload)); 148 | 149 | #ifdef I2C_LCD 150 | lcd.setCursor(0,1); 151 | lcd.print("S: "); 152 | lcd.setCursor(2,1); 153 | lcd.print(SendPayload); 154 | #endif 155 | 156 | Serial.print("S:"); 157 | Serial.print(SendPayload); 158 | Serial.println(); 159 | stringComplete = false; 160 | 161 | // restore TX & Rx addr for reading 162 | radio.openWritingPipe(pipes[0]); 163 | radio.openReadingPipe(1,pipes[1]); 164 | radio.startListening(); 165 | SendPayload[0] = 0; 166 | dataBufferIndex = 0; 167 | } // endif 168 | } // end serial_receive() 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/pingpair_ack/pingpair_ack.ino: -------------------------------------------------------------------------------- 1 | /* 2 | // March 2014 - TMRh20 - Updated along with High Speed RF24 Library fork 3 | // Parts derived from examples by J. Coliz 4 | */ 5 | /** 6 | * Example for efficient call-response using ack-payloads 7 | * 8 | * This example continues to make use of all the normal functionality of the radios including 9 | * the auto-ack and auto-retry features, but allows ack-payloads to be written optionlly as well. 10 | * This allows very fast call-response communication, with the responding radio never having to 11 | * switch out of Primary Receiver mode to send back a payload, but having the option to if wanting 12 | * to initiate communication instead of respond to a commmunication. 13 | */ 14 | 15 | 16 | 17 | #include 18 | #include "nRF24L01.h" 19 | #include "RF24.h" 20 | #include "printf.h" 21 | 22 | // Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins CE 8, CSN 9 23 | // This is for UNO Adapter, pin 10 is Vcc 24 | RF24 radio(8,9); 25 | 26 | // Topology 27 | const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL }; // Radio pipe addresses for the 2 nodes to communicate. 28 | 29 | // Role management: Set up role. This sketch uses the same software for all the nodes 30 | // in this system. Doing so greatly simplifies testing. 31 | 32 | typedef enum { role_ping_out = 1, role_pong_back } role_e; // The various roles supported by this sketch 33 | const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; // The debug-friendly names of those roles 34 | role_e role = role_pong_back; // The role of the current running sketch 35 | 36 | // A single byte to keep track of the data being sent back and forth 37 | byte counter = 1; 38 | 39 | void setup(){ 40 | 41 | // Simple codes for UNO nRF adapter that uses pin 10 as Vcc 42 | pinMode(10,OUTPUT); 43 | digitalWrite(10,HIGH); 44 | delay(500); 45 | 46 | 47 | Serial.begin(57600); 48 | printf_begin(); 49 | printf("\n\rRF24/examples/GettingStarted/\n\r"); 50 | printf("ROLE: %s\n\r",role_friendly_name[role]); 51 | printf("*** PRESS 'T' to begin transmitting to the other node\n\r"); 52 | 53 | // Setup and configure rf radio 54 | 55 | radio.begin(); 56 | radio.setAutoAck(1); // Ensure autoACK is enabled 57 | radio.enableAckPayload(); // Allow optional ack payloads 58 | radio.setRetries(0,15); // Smallest time between retries, max no. of retries 59 | radio.setPayloadSize(1); // Here we are sending 1-byte payloads to test the call-response speed 60 | radio.openWritingPipe(pipes[1]); // Both radios listen on the same pipes by default, and switch when writing 61 | radio.openReadingPipe(1,pipes[0]); 62 | radio.startListening(); // Start listening 63 | radio.printDetails(); // Dump the configuration of the rf unit for debugging 64 | } 65 | 66 | void loop(void) { 67 | 68 | if (role == role_ping_out){ 69 | 70 | radio.stopListening(); // First, stop listening so we can talk. 71 | 72 | printf("Now sending %d as payload. ",counter); 73 | byte gotByte; 74 | unsigned long time = micros(); // Take the time, and send it. This will block until complete 75 | //Called when STANDBY-I mode is engaged (User is finished sending) 76 | if (!radio.write( &counter, 1 )){ 77 | printf("failed.\n\r"); 78 | }else{ 79 | 80 | if(!radio.available()){ 81 | printf("Blank Payload Received\n\r"); 82 | }else{ 83 | while(radio.available() ){ 84 | unsigned long tim = micros(); 85 | radio.read( &gotByte, 1 ); 86 | printf("Got response %d, round-trip delay: %lu microseconds\n\r",gotByte,tim-time); 87 | counter++; 88 | } 89 | } 90 | 91 | } 92 | // Try again later 93 | delay(1000); 94 | } 95 | 96 | // Pong back role. Receive each packet, dump it out, and send it back 97 | 98 | if ( role == role_pong_back ) { 99 | byte pipeNo; 100 | byte gotByte; // Dump the payloads until we've gotten everything 101 | while( radio.available(&pipeNo)){ 102 | radio.read( &gotByte, 1 ); 103 | radio.writeAckPayload(pipeNo,&gotByte, 1 ); 104 | } 105 | } 106 | 107 | // Change roles 108 | 109 | if ( Serial.available() ) 110 | { 111 | char c = toupper(Serial.read()); 112 | if ( c == 'T' && role == role_pong_back ) 113 | { 114 | printf("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK\n\r"); 115 | 116 | role = role_ping_out; // Become the primary transmitter (ping out) 117 | radio.openWritingPipe(pipes[0]); 118 | radio.openReadingPipe(1,pipes[1]); 119 | } 120 | else if ( c == 'R' && role == role_ping_out ) 121 | { 122 | printf("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK\n\r"); 123 | 124 | role = role_pong_back; // Become the primary receiver (pong back) 125 | radio.openWritingPipe(pipes[1]); 126 | radio.openReadingPipe(1,pipes[0]); 127 | radio.startListening(); 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /С обратной связью и защитой связи/pyroRX/pyroRX.ino: -------------------------------------------------------------------------------- 1 | /* Данный скетч делает следующее: передатчик (TX) отправляет массив 2 | данных, который генерируется согласно показаниям с кнопки и с 3 | двух потенциомтеров. Приёмник (RX) получает массив, и записывает 4 | данные на реле, сервомашинку и генерирует ШИМ сигнал на транзистор. 5 | by AlexGyver 2016 6 | */ 7 | 8 | #include 9 | #include "nRF24L01.h" 10 | #include "RF24.h" 11 | 12 | float my_vcc_const = 1.1; // начальное значение константы должно быть 1.1 13 | 14 | byte MOSFET[10] = {18, 4, 5, 6, 7, 8, 14, 15, 16, 17}; //массив пинов, к которым подключены мосфеты 15 | boolean FLAGS[10]; // массив, хранящий время для таймера каждого мосфета? по умолчанию {0,0,0,0,0,0,0,0} 16 | unsigned long TIMES[10]; // массив, хранящий состояния мосфетов 17 | byte battery_pin = 6; // сюда подключен аккумулятор для измерения напряжения 18 | boolean RXstate; 19 | 20 | byte receiv_data[2]; 21 | 22 | int fuse_time = 1500; // время в миллисекундах, которое ток будет подаваться на спираль 23 | int battery_check = 2800; // нижняя граница заряда аккумулятора для защиты, в милливольтах! 24 | 25 | byte crypt_key = 123; // уникальный ключ для защиты связи 26 | int check = 111; // условный код, для обратной связи 27 | 28 | RF24 radio(9, 10); // "создать" модуль на пинах 9 и 10 Для Уно 29 | //RF24 radio(9,53); // для Меги 30 | 31 | byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"}; //возможные номера труб 32 | 33 | void setup() { 34 | Serial.begin(9600); //открываем порт для связи с ПК 35 | 36 | // настраиваем пины мосфетов как выходы по массиву 37 | for (int i = 0; i <= 9; i++) { 38 | pinMode(MOSFET[i], OUTPUT); 39 | } 40 | 41 | radio.begin(); //активировать модуль 42 | radio.setAutoAck(1); //режим подтверждения приёма, 1 вкл 0 выкл 43 | radio.setRetries(0, 15); //(время между попыткой достучаться, число попыток) 44 | radio.enableAckPayload(); //разрешить отсылку данных в ответ на входящий сигнал 45 | radio.setPayloadSize(32); //размер пакета, в байтах 46 | 47 | radio.openReadingPipe(1, address[0]); //хотим слушать трубу 0 48 | radio.setChannel(0x60); //выбираем канал (в котором нет шумов!) 49 | 50 | radio.setPALevel (RF24_PA_MAX); //уровень мощности передатчика. На выбор RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX 51 | radio.setDataRate (RF24_1MBPS); //скорость обмена. На выбор RF24_2MBPS, RF24_1MBPS, RF24_250KBPS 52 | //должна быть одинакова на приёмнике и передатчике! 53 | //при самой низкой скорости имеем самую высокую чувствительность и дальность!! 54 | 55 | radio.powerUp(); //начать работу 56 | radio.startListening(); //начинаем слушать эфир, мы приёмный модуль 57 | } 58 | 59 | void loop() { 60 | byte pipeNo; 61 | while ( radio.available(&pipeNo)) { // слушаем эфир со всех труб 62 | radio.read( &receiv_data, sizeof(receiv_data) ); // читаем входящий сигнал 63 | 64 | if (receiv_data[0] == crypt_key) { 65 | 66 | if (receiv_data[1] == check) { 67 | int voltage = analogRead(battery_pin) * readVcc() / 1024; 68 | if (voltage > battery_check) RXstate = 1; else RXstate = 0; 69 | 70 | radio.writeAckPayload(pipeNo, &RXstate, sizeof(RXstate) ); 71 | Serial.println("Check state sent"); 72 | } else { 73 | if (FLAGS[receiv_data[1]] == 0) { 74 | FLAGS[receiv_data[1]] = 1; // поднять флаг для мосфета, по входящему сигналу 75 | TIMES[receiv_data[1]] = millis(); // запомнить время прихода сигнала 76 | digitalWrite(MOSFET[receiv_data[1]], HIGH); // подать питание на мосфет (на запал) 77 | 78 | Serial.print("Fuse #"); Serial.print(receiv_data[1]); Serial.println(" ON"); 79 | } 80 | } 81 | } 82 | } 83 | 84 | for (int i = 0; i <= 9; i++) { // пройтись по всем 10ти мосфетам 85 | if (millis() - TIMES[i] > fuse_time && FLAGS[i] == 1) { // если время с момента открытия мосфета > заданного 86 | FLAGS[i] = 0; // опустить флаг 87 | digitalWrite(MOSFET[i], LOW); // закрыть мосфет, погасить запал 88 | Serial.print("Fuse #"); Serial.print(i); Serial.println(" OFF"); 89 | } 90 | } 91 | } 92 | 93 | long readVcc() { //функция чтения внутреннего опорного напряжения, универсальная (для всех ардуин) 94 | #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) 95 | ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); 96 | #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) 97 | ADMUX = _BV(MUX5) | _BV(MUX0); 98 | #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) 99 | ADMUX = _BV(MUX3) | _BV(MUX2); 100 | #else 101 | ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); 102 | #endif 103 | delay(2); // Wait for Vref to settle 104 | ADCSRA |= _BV(ADSC); // Start conversion 105 | while (bit_is_set(ADCSRA, ADSC)); // measuring 106 | uint8_t low = ADCL; // must read ADCL first - it then locks ADCH 107 | uint8_t high = ADCH; // unlocks both 108 | long result = (high << 8) | low; 109 | 110 | result = my_vcc_const * 1023 * 1000 / result; // расчёт реального VCC 111 | return result; // возвращает VCC 112 | } 113 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/scanner/Jamfile: -------------------------------------------------------------------------------- 1 | # (1) Project Information 2 | 3 | PROJECT_LIBS = SPI RF24 ; 4 | 5 | # (2) Board Information 6 | 7 | UPLOAD_PROTOCOL ?= stk500v1 ; 8 | UPLOAD_SPEED ?= 57600 ; 9 | MCU ?= atmega328p ; 10 | F_CPU ?= 16000000 ; 11 | CORE ?= arduino ; 12 | VARIANT ?= standard ; 13 | ARDUINO_VERSION ?= 100 ; 14 | 15 | # (3) USB Ports 16 | 17 | PORTS = p4 p6 p9 u0 u1 u2 ; 18 | PORT_p6 = /dev/tty.usbserial-A600eHIs ; 19 | PORT_p4 = /dev/tty.usbserial-A40081RP ; 20 | PORT_p9 = /dev/tty.usbserial-A9007LmI ; 21 | PORT_u0 = /dev/ttyUSB0 ; 22 | PORT_u1 = /dev/ttyUSB1 ; 23 | PORT_u2 = /dev/ttyUSB2 ; 24 | 25 | # (4) Location of AVR tools 26 | # 27 | # This configuration assumes using avr-tools that were obtained separate from the Arduino 28 | # distribution. 29 | 30 | if $(OS) = MACOSX 31 | { 32 | AVR_BIN = /usr/local/avrtools/bin ; 33 | AVR_ETC = /usr/local/avrtools/etc ; 34 | AVR_INCLUDE = /usr/local/avrtools/include ; 35 | } 36 | else 37 | { 38 | AVR_BIN = /usr/bin ; 39 | AVR_INCLUDE = /usr/lib/avr/include ; 40 | AVR_ETC = /etc ; 41 | } 42 | 43 | # (5) Directories where Arduino core and libraries are located 44 | 45 | ARDUINO_DIR ?= /opt/Arduino ; 46 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ; 47 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 48 | SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; 49 | 50 | # 51 | # -------------------------------------------------- 52 | # Below this line usually never needs to be modified 53 | # 54 | 55 | # Tool locations 56 | 57 | CC = $(AVR_BIN)/avr-gcc ; 58 | C++ = $(AVR_BIN)/avr-g++ ; 59 | LINK = $(AVR_BIN)/avr-gcc ; 60 | OBJCOPY = $(AVR_BIN)/avr-objcopy ; 61 | AVRDUDE = $(AVR_BIN)/avrdude ; 62 | 63 | # Flags 64 | 65 | DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; 66 | OPTIM = -Os ; 67 | CCFLAGS = -Wall -Wextra -mmcu=$(MCU) -ffunction-sections -fdata-sections ; 68 | C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ; 69 | LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ; 70 | AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ; 71 | 72 | # Search everywhere for headers 73 | 74 | HDRS = $(PWD) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ; 75 | 76 | # Output locations 77 | 78 | LOCATE_TARGET = $(F_CPU) ; 79 | LOCATE_SOURCE = $(F_CPU) ; 80 | 81 | # 82 | # Custom rules 83 | # 84 | 85 | rule GitVersion 86 | { 87 | Always $(<) ; 88 | Depends all : $(<) ; 89 | } 90 | 91 | actions GitVersion 92 | { 93 | echo "const char program_version[] = \"\\" > $(<) 94 | git log -1 --pretty=format:%h >> $(<) 95 | echo "\";" >> $(<) 96 | } 97 | 98 | GitVersion version.h ; 99 | 100 | rule Pde 101 | { 102 | Depends $(<) : $(>) ; 103 | MakeLocate $(<) : $(LOCATE_SOURCE) ; 104 | Clean clean : $(<) ; 105 | } 106 | 107 | if ( $(ARDUINO_VERSION) < 100 ) 108 | { 109 | ARDUINO_H = WProgram.h ; 110 | } 111 | else 112 | { 113 | ARDUINO_H = Arduino.h ; 114 | } 115 | 116 | actions Pde 117 | { 118 | echo "#include <$(ARDUINO_H)>" > $(<) 119 | echo "#line 1 \"$(>)\"" >> $(<) 120 | cat $(>) >> $(<) 121 | } 122 | 123 | rule C++Pde 124 | { 125 | local _CPP = $(>:B).cpp ; 126 | Pde $(_CPP) : $(>) ; 127 | C++ $(<) : $(_CPP) ; 128 | } 129 | 130 | rule UserObject 131 | { 132 | switch $(>:S) 133 | { 134 | case .ino : C++Pde $(<) : $(>) ; 135 | case .pde : C++Pde $(<) : $(>) ; 136 | } 137 | } 138 | 139 | rule Objects 140 | { 141 | local _i ; 142 | 143 | for _i in [ FGristFiles $(<) ] 144 | { 145 | local _b = $(_i:B)$(SUFOBJ) ; 146 | local _o = $(_b:G=$(SOURCE_GRIST:E)) ; 147 | Object $(_o) : $(_i) ; 148 | Depends obj : $(_o) ; 149 | } 150 | } 151 | 152 | rule Main 153 | { 154 | MainFromObjects $(<) : $(>:B)$(SUFOBJ) ; 155 | Objects $(>) ; 156 | } 157 | 158 | rule Hex 159 | { 160 | Depends $(<) : $(>) ; 161 | MakeLocate $(<) : $(LOCATE_TARGET) ; 162 | Depends hex : $(<) ; 163 | Clean clean : $(<) ; 164 | } 165 | 166 | actions Hex 167 | { 168 | $(OBJCOPY) -O ihex -R .eeprom $(>) $(<) 169 | } 170 | 171 | rule Upload 172 | { 173 | Depends $(1) : $(2) ; 174 | Depends $(2) : $(3) ; 175 | NotFile $(1) ; 176 | Always $(1) ; 177 | Always $(2) ; 178 | UploadAction $(2) : $(3) ; 179 | } 180 | 181 | actions UploadAction 182 | { 183 | $(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 184 | } 185 | 186 | # 187 | # Targets 188 | # 189 | 190 | # Grab everything from the core directory 191 | CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 192 | 193 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 194 | # can specify specific modules to pick up in PROJECT_MODULES 195 | LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; 196 | 197 | # Grab everything from the current dir 198 | PROJECT_MODULES += [ GLOB $(PWD) : *.c *.cpp *.pde *.ino ] ; 199 | 200 | # Main output executable 201 | MAIN = $(PWD:B).elf ; 202 | 203 | Main $(MAIN) : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; 204 | Hex $(MAIN:B).hex : $(MAIN) ; 205 | 206 | # Upload targets 207 | for _p in $(PORTS) 208 | { 209 | Upload $(_p) : $(PORT_$(_p)) : $(MAIN:B).hex ; 210 | } 211 | -------------------------------------------------------------------------------- /С обратной связью/pyroTX/pyroTX.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Created 2017 3 | by AlexGyver 4 | AlexGyver Home Labs Inc. 5 | */ 6 | #include "Keypad.h" //библиотека клавиатуры 7 | #include // библиотека для работы с шиной SPI 8 | #include "nRF24L01.h" // библиотека радиомодуля 9 | #include "RF24.h" // ещё библиотека радиомодуля 10 | 11 | RF24 radio(9, 10); // "создать" модуль на пинах 9 и 10 Для Уно 12 | byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"}; //возможные номера труб 13 | 14 | byte redLED = 14; 15 | byte greenLED = 15; 16 | 17 | int check = 111; 18 | boolean check_answer; 19 | 20 | const byte ROWS = 4; //4 строки у клавиатуры 21 | const byte COLS = 3; //три столбца 22 | char keys[4][3] = { 23 | {'1', '2', '3'}, 24 | {'4', '5', '6'}, 25 | {'7', '8', '9'}, 26 | {'*', '0', '#'} 27 | }; 28 | byte rowPins[ROWS] = {8, 7, 6, 5}; //Подключены строки (4 пина) 29 | byte colPins[COLS] = {4, 3, 2}; //подключены столбцы (3 пина) 30 | Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); //создать клавиатуру 31 | boolean flag; 32 | 33 | void setup() { 34 | Serial.begin(9600); 35 | 36 | pinMode(redLED, OUTPUT); 37 | pinMode(greenLED, OUTPUT); 38 | digitalWrite(greenLED, HIGH); // зажечь зелёный светодиод 39 | 40 | radio.begin(); //активировать модуль 41 | radio.setAutoAck(1); //режим подтверждения приёма, 1 вкл 0 выкл 42 | radio.setRetries(0, 15); //(время между попыткой достучаться, число попыток) 43 | radio.enableAckPayload(); //разрешить отсылку данных в ответ на входящий сигнал 44 | radio.setPayloadSize(32); //размер пакета, в байтах 45 | 46 | radio.openWritingPipe(address[0]); //мы - труба 0, открываем канал для передачи данных 47 | radio.setChannel(0x60); //выбираем канал (в котором нет шумов!) 48 | 49 | radio.setPALevel (RF24_PA_MAX); //уровень мощности передатчика. На выбор RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX 50 | radio.setDataRate (RF24_1MBPS); //скорость обмена. На выбор RF24_2MBPS, RF24_1MBPS, RF24_250KBPS 51 | //должна быть одинакова на приёмнике и передатчике! 52 | //при самой низкой скорости имеем самую высокую чувствительность и дальность!! 53 | 54 | radio.powerUp(); //начать работу 55 | radio.stopListening(); //не слушаем радиоэфир, мы передатчик 56 | } 57 | 58 | void loop() { 59 | byte gotByte; 60 | char key = keypad.waitForKey(); // ожидать ввод с клавиатуры, принять символ 61 | int keyInt = key - '0'; // перевести символ в целочисленный тип 62 | 63 | if (keyInt >= 0 && keyInt <= 9 && flag == 1) { // если число от 0 до 9 и флаг поднят 64 | digitalWrite(greenLED, HIGH); // включить зелёный светодиод 65 | digitalWrite(redLED, LOW); // погасить красный светодиод 66 | radio.write(&keyInt, sizeof(keyInt)); // отправить цифру с клавиатуры по радио 67 | delay(10); 68 | digitalWrite(greenLED, LOW); // погасить зелёный светодиод 69 | digitalWrite(redLED, HIGH); // зажечь красный светодиод 70 | 71 | } else if (key == '*') { // если символ * 72 | flag = 0; // опустить флаг 73 | 74 | digitalWrite(redLED, LOW); // погасить красный светодиод 75 | digitalWrite(greenLED, LOW); // погасить зелёный светодиод 76 | delay(100); // задержка для эпичности 77 | 78 | if ( radio.write(&check, sizeof(check)) ) { // отправляем значение 111 79 | if (!radio.available()) { // если не получаем ответ 80 | Serial.println("No answer"); 81 | digitalWrite(greenLED, HIGH); // включить зелёный светодиод 82 | } else { 83 | while (radio.available() ) { // если в ответе что-то есть 84 | radio.read( &check_answer, 1); // читаем 85 | if (check_answer == 1) { // если статус = 1 (готов к работе) 86 | flag = 1; // поднять флаг готовности к работе 87 | digitalWrite(redLED, HIGH); // зажечь красный светодиод 88 | Serial.println("Status OK"); 89 | } else { // если статус = 0 (акум разряжен) 90 | Serial.println("Status BAD"); 91 | for (int i = 0; i < 5; i++) { // моргнуть 6 раз зелёным светодиодом 92 | digitalWrite(greenLED, HIGH); 93 | delay(200); 94 | digitalWrite(greenLED, LOW); 95 | delay(100); 96 | } 97 | digitalWrite(greenLED, HIGH); // включить зелёный светодиод при ошибке 98 | } 99 | } 100 | } 101 | } else { 102 | Serial.println("Sending failed"); // ошибка отправки 103 | digitalWrite(greenLED, HIGH); // включить зелёный светодиод 104 | } 105 | 106 | } else if (key == '#') { // если символ № 107 | flag = 0; // опустить флаг 108 | digitalWrite(greenLED, HIGH); // зажечь зелёный светодиод 109 | digitalWrite(redLED, LOW); // погасить красный светодиод 110 | } 111 | } 112 | 113 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/Usage/nordic_fob/Jamfile: -------------------------------------------------------------------------------- 1 | # (1) Project Information 2 | 3 | PROJECT_LIBS = RF24 SPI ; 4 | PROJECT_DIRS = $(PWD) ; 5 | 6 | # (2) Board Information 7 | 8 | UPLOAD_PROTOCOL ?= stk500v1 ; 9 | UPLOAD_SPEED ?= 115200 ; 10 | MCU ?= atmega328p ; 11 | F_CPU ?= 16000000 ; 12 | CORE ?= arduino ; 13 | VARIANT ?= standard ; 14 | ARDUINO_VERSION ?= 100 ; 15 | 16 | # (3) USB Ports 17 | 18 | PORTS = p4 p6 p9 u0 u1 u2 ; 19 | PORT_p6 = /dev/tty.usbserial-A600eHIs ; 20 | PORT_p4 = /dev/tty.usbserial-A40081RP ; 21 | PORT_p9 = /dev/tty.usbserial-A9007LmI ; 22 | PORT_u0 = /dev/ttyUSB0 ; 23 | PORT_u1 = /dev/ttyUSB1 ; 24 | PORT_u2 = /dev/ttyUSB2 ; 25 | 26 | # (4) Location of AVR tools 27 | # 28 | # This configuration assumes using avr-tools that were obtained separate from the Arduino 29 | # distribution. 30 | 31 | if $(OS) = MACOSX 32 | { 33 | AVR_BIN = /usr/local/avrtools/bin ; 34 | AVR_ETC = /usr/local/avrtools/etc ; 35 | AVR_INCLUDE = /usr/local/avrtools/include ; 36 | } 37 | else 38 | { 39 | AVR_BIN = /usr/bin ; 40 | AVR_INCLUDE = /usr/lib/avr/include ; 41 | AVR_ETC = /etc ; 42 | } 43 | 44 | # (5) Directories where Arduino core and libraries are located 45 | 46 | ARDUINO_DIR ?= /opt/Arduino ; 47 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ; 48 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 49 | SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; 50 | 51 | # 52 | # -------------------------------------------------- 53 | # Below this line usually never needs to be modified 54 | # 55 | 56 | # Tool locations 57 | 58 | CC = $(AVR_BIN)/avr-gcc ; 59 | C++ = $(AVR_BIN)/avr-g++ ; 60 | LINK = $(AVR_BIN)/avr-gcc ; 61 | AR = $(AVR_BIN)/avr-ar rcs ; 62 | RANLIB = ; 63 | OBJCOPY = $(AVR_BIN)/avr-objcopy ; 64 | AVRDUDE = $(AVR_BIN)/avrdude ; 65 | 66 | # Flags 67 | 68 | DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; 69 | OPTIM = -Os ; 70 | CCFLAGS = -Wall -Wextra -Wno-strict-aliasing -mmcu=$(MCU) -ffunction-sections -fdata-sections ; 71 | C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ; 72 | LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ; 73 | AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ; 74 | 75 | # Search everywhere for headers 76 | 77 | HDRS = $(PROJECT_DIRS) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ; 78 | 79 | # Output locations 80 | 81 | LOCATE_TARGET = $(F_CPU) ; 82 | LOCATE_SOURCE = $(F_CPU) ; 83 | 84 | # 85 | # Custom rules 86 | # 87 | 88 | rule GitVersion 89 | { 90 | Always $(<) ; 91 | Depends all : $(<) ; 92 | } 93 | 94 | actions GitVersion 95 | { 96 | echo "const char program_version[] = \"\\" > $(<) 97 | git log -1 --pretty=format:%h >> $(<) 98 | echo "\";" >> $(<) 99 | } 100 | 101 | GitVersion version.h ; 102 | 103 | rule Pde 104 | { 105 | Depends $(<) : $(>) ; 106 | MakeLocate $(<) : $(LOCATE_SOURCE) ; 107 | Clean clean : $(<) ; 108 | } 109 | 110 | if ( $(ARDUINO_VERSION) < 100 ) 111 | { 112 | ARDUINO_H = WProgram.h ; 113 | } 114 | else 115 | { 116 | ARDUINO_H = Arduino.h ; 117 | } 118 | 119 | actions Pde 120 | { 121 | echo "#include <$(ARDUINO_H)>" > $(<) 122 | echo "#line 1 \"$(>)\"" >> $(<) 123 | cat $(>) >> $(<) 124 | } 125 | 126 | rule C++Pde 127 | { 128 | local _CPP = $(>:B).cpp ; 129 | Pde $(_CPP) : $(>) ; 130 | C++ $(<) : $(_CPP) ; 131 | } 132 | 133 | rule UserObject 134 | { 135 | switch $(>:S) 136 | { 137 | case .ino : C++Pde $(<) : $(>) ; 138 | case .pde : C++Pde $(<) : $(>) ; 139 | } 140 | } 141 | 142 | rule Objects 143 | { 144 | local _i ; 145 | 146 | for _i in [ FGristFiles $(<) ] 147 | { 148 | local _b = $(_i:B)$(SUFOBJ) ; 149 | local _o = $(_b:G=$(SOURCE_GRIST:E)) ; 150 | Object $(_o) : $(_i) ; 151 | Depends obj : $(_o) ; 152 | } 153 | } 154 | 155 | rule Library 156 | { 157 | LibraryFromObjects $(<) : $(>:B)$(SUFOBJ) ; 158 | Objects $(>) ; 159 | } 160 | 161 | rule Main 162 | { 163 | MainFromObjects $(<) : $(>:B)$(SUFOBJ) ; 164 | Objects $(>) ; 165 | } 166 | 167 | rule Hex 168 | { 169 | Depends $(<) : $(>) ; 170 | MakeLocate $(<) : $(LOCATE_TARGET) ; 171 | Depends hex : $(<) ; 172 | Clean clean : $(<) ; 173 | } 174 | 175 | actions Hex 176 | { 177 | $(OBJCOPY) -O ihex -R .eeprom $(>) $(<) 178 | } 179 | 180 | rule Upload 181 | { 182 | Depends $(1) : $(2) ; 183 | Depends $(2) : $(3) ; 184 | NotFile $(1) ; 185 | Always $(1) ; 186 | Always $(2) ; 187 | UploadAction $(2) : $(3) ; 188 | } 189 | 190 | actions UploadAction 191 | { 192 | $(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 193 | } 194 | 195 | rule Arduino 196 | { 197 | LINKFLAGS on $(<) = $(LINKFLAGS) -Wl,-Map=$(LOCATE_TARGET)/$(<:B).map ; 198 | Main $(<) : $(>) ; 199 | LinkLibraries $(<) : libs core ; 200 | Hex $(<:B).hex : $(<) ; 201 | for _p in $(PORTS) 202 | { 203 | Upload $(_p) : $(PORT_$(_p)) : $(<:B).hex ; 204 | } 205 | } 206 | 207 | # 208 | # Targets 209 | # 210 | 211 | # Grab everything from the core directory 212 | Library core : [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 213 | 214 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 215 | # can specify specific modules to pick up in PROJECT_MODULES 216 | Library libs : [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; 217 | 218 | # Main output executable 219 | Arduino $(PWD:B).elf : $(PROJECT_MODULES) [ GLOB $(PROJECT_DIRS) : *.c *.cpp *.pde *.ino ] ; 220 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/pingpair_irq/pingpair_irq.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example of using interrupts 11 | * 12 | * This is an example of how to user interrupts to interact with the radio. 13 | * It builds on the pingpair_pl example, and uses ack payloads. 14 | */ 15 | 16 | #include 17 | #include "nRF24L01.h" 18 | #include "RF24.h" 19 | #include "printf.h" 20 | 21 | // 22 | // Hardware configuration 23 | // 24 | 25 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 26 | 27 | RF24 radio(8,9); 28 | 29 | // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver 30 | // Leave open to be the 'ping' transmitter 31 | const short role_pin = 7; 32 | 33 | // 34 | // Topology 35 | // 36 | 37 | // Single radio pipe address for the 2 nodes to communicate. 38 | const uint64_t pipe = 0xE8E8F0F0E1LL; 39 | 40 | // 41 | // Role management 42 | // 43 | // Set up role. This sketch uses the same software for all the nodes in this 44 | // system. Doing so greatly simplifies testing. The hardware itself specifies 45 | // which node it is. 46 | // 47 | // This is done through the role_pin 48 | // 49 | 50 | // The various roles supported by this sketch 51 | typedef enum { role_sender = 1, role_receiver } role_e; 52 | 53 | // The debug-friendly names of those roles 54 | const char* role_friendly_name[] = { "invalid", "Sender", "Receiver"}; 55 | 56 | // The role of the current running sketch 57 | role_e role; 58 | 59 | // Interrupt handler, check the radio because we got an IRQ 60 | void check_radio(void); 61 | 62 | void setup(void) 63 | { 64 | // 65 | // Role 66 | // 67 | 68 | // set up the role pin 69 | pinMode(role_pin, INPUT); 70 | digitalWrite(role_pin,HIGH); 71 | delay(20); // Just to get a solid reading on the role pin 72 | 73 | // read the address pin, establish our role 74 | if ( digitalRead(role_pin) ) 75 | role = role_sender; 76 | else 77 | role = role_receiver; 78 | 79 | // 80 | // Print preamble 81 | // 82 | 83 | Serial.begin(57600); 84 | printf_begin(); 85 | printf("\n\rRF24/examples/pingpair_irq/\n\r"); 86 | printf("ROLE: %s\n\r",role_friendly_name[role]); 87 | 88 | // 89 | // Setup and configure rf radio 90 | // 91 | 92 | radio.begin(); 93 | 94 | // We will be using the Ack Payload feature, so please enable it 95 | radio.enableAckPayload(); 96 | 97 | // 98 | // Open pipes to other nodes for communication 99 | // 100 | 101 | // This simple sketch opens a single pipe for these two nodes to communicate 102 | // back and forth. One listens on it, the other talks to it. 103 | 104 | if ( role == role_sender ) 105 | { 106 | radio.openWritingPipe(pipe); 107 | } 108 | else 109 | { 110 | radio.openReadingPipe(1,pipe); 111 | } 112 | 113 | // 114 | // Start listening 115 | // 116 | 117 | if ( role == role_receiver ) 118 | radio.startListening(); 119 | 120 | // 121 | // Dump the configuration of the rf unit for debugging 122 | // 123 | 124 | radio.printDetails(); 125 | 126 | // 127 | // Attach interrupt handler to interrupt #0 (using pin 2) 128 | // on BOTH the sender and receiver 129 | // 130 | 131 | attachInterrupt(0, check_radio, FALLING); 132 | } 133 | 134 | static uint32_t message_count = 0; 135 | 136 | void loop(void) 137 | { 138 | // 139 | // Sender role. Repeatedly send the current time 140 | // 141 | 142 | if (role == role_sender) 143 | { 144 | // Take the time, and send it. 145 | unsigned long time = millis(); 146 | printf("Now sending %lu\n\r",time); 147 | radio.powerUp() ; 148 | radio.startWrite( &time, sizeof(unsigned long) ); 149 | 150 | // Try again soon 151 | delay(1000); 152 | } 153 | 154 | // 155 | // Receiver role: Does nothing! All the work is in IRQ 156 | // 157 | 158 | } 159 | 160 | void check_radio(void) 161 | { 162 | // What happened? 163 | bool tx,fail,rx; 164 | radio.whatHappened(tx,fail,rx); 165 | 166 | // Have we successfully transmitted? 167 | if ( tx ) 168 | { 169 | if ( role == role_sender ) 170 | printf("Send:OK\n\r"); 171 | 172 | if ( role == role_receiver ) 173 | printf("Ack Payload:Sent\n\r"); 174 | } 175 | 176 | // Have we failed to transmit? 177 | if ( fail ) 178 | { 179 | if ( role == role_sender ) 180 | printf("Send:Failed\n\r"); 181 | 182 | if ( role == role_receiver ) 183 | printf("Ack Payload:Failed\n\r"); 184 | } 185 | 186 | // Transmitter can power down for now, because 187 | // the transmission is done. 188 | if ( ( tx || fail ) && ( role == role_sender ) ) 189 | radio.powerDown(); 190 | 191 | // Did we receive a message? 192 | if ( rx ) 193 | { 194 | // If we're the sender, we've received an ack payload 195 | if ( role == role_sender ) 196 | { 197 | radio.read(&message_count,sizeof(message_count)); 198 | printf("Ack:%lu\n\r",message_count); 199 | } 200 | 201 | // If we're the receiver, we've received a time message 202 | if ( role == role_receiver ) 203 | { 204 | // Get this payload and dump it 205 | static unsigned long got_time; 206 | radio.read( &got_time, sizeof(got_time) ); 207 | printf("Got payload %lu\n\r",got_time); 208 | 209 | // Add an ack packet for the next time around. This is a simple 210 | // packet counter 211 | radio.writeAckPayload( 1, &message_count, sizeof(message_count) ); 212 | ++message_count; 213 | } 214 | } 215 | } 216 | 217 | // vim:ai:cin:sts=2 sw=2 ft=cpp 218 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/Usage/led_remote/Jamfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = $(PWD:B) ; 2 | PROJECT_DIR = . ; 3 | PROJECT_LIBS = SPI RF24 ; 4 | 5 | OUT_DIR = ojam ; 6 | F_CPU = 16000000 ; 7 | MCU = atmega328p ; 8 | PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; 9 | 10 | UPLOAD_RATE = 57600 ; 11 | AVRDUDE_PROTOCOL = stk500v1 ; 12 | COM = 33 ; 13 | 14 | # Host-specific overrides for locations 15 | if $(OS) = MACOSX 16 | { 17 | ARDUINO_VERSION = 22 ; 18 | OLD_DIR = /opt/arduino-0021 ; 19 | AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; 20 | AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; 21 | ARDUINO_DIR = /opt/Arduino ; 22 | ARDUINO_AVR = /usr/lib/avr/include ; 23 | } 24 | 25 | # Where is everything? 26 | ARDUINO_VERSION ?= 22 ; 27 | AVR_TOOLS_PATH ?= /usr/bin ; 28 | ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; 29 | ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; 30 | AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; 31 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ; 32 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 33 | SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; 34 | AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; 35 | AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; 36 | AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; 37 | AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; 38 | AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; 39 | 40 | DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; 41 | CTUNING = -ffunction-sections -fdata-sections ; 42 | CXXTUNING = -fno-exceptions -fno-strict-aliasing ; 43 | CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ; 44 | CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; 45 | LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; 46 | 47 | # Search everywhere for headers 48 | HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; 49 | 50 | # Grab everything from the core directory 51 | CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 52 | 53 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 54 | # can specify specific modules to pick up in PROJECT_MODULES 55 | LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ; 56 | 57 | # In addition to explicitly-specified program modules, pick up anything from the current 58 | # dir. 59 | PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; 60 | 61 | # Shortcut for the out files 62 | OUT = $(OUT_DIR)/$(PROJECT_NAME) ; 63 | 64 | # AvrDude setup 65 | AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; 66 | 67 | rule GitVersion 68 | { 69 | Always $(<) ; 70 | Depends all : $(<) ; 71 | } 72 | 73 | actions GitVersion 74 | { 75 | echo "const char program_version[] = \"\\" > $(<) 76 | git log -1 --pretty=format:%h >> $(<) 77 | echo "\";" >> $(<) 78 | } 79 | 80 | GitVersion version.h ; 81 | 82 | rule AvrCc 83 | { 84 | Depends $(<) : $(>) ; 85 | Depends $(<) : $(<:D) ; 86 | Clean clean : $(<) ; 87 | 88 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 89 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 90 | } 91 | 92 | actions AvrCc 93 | { 94 | $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) 95 | } 96 | 97 | rule AvrC++ 98 | { 99 | Depends $(<) : $(>) ; 100 | Depends $(<) : $(<:D) ; 101 | Clean clean : $(<) ; 102 | 103 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 104 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 105 | } 106 | 107 | actions AvrC++ 108 | { 109 | $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) 110 | } 111 | 112 | rule Pde 113 | { 114 | Depends $(<) : $(>) ; 115 | Depends $(<) : $(<:D) ; 116 | Clean clean : $(<) ; 117 | 118 | } 119 | 120 | actions Pde 121 | { 122 | echo "#include " > $(<) 123 | echo "#line 1 \"$(>)\"" >> $(<) 124 | cat $(>) >> $(<) 125 | } 126 | 127 | rule AvrPde 128 | { 129 | local _CPP = $(OUT_DIR)/$(_I:B).cpp ; 130 | Pde $(_CPP) : $(>) ; 131 | AvrC++ $(<) : $(_CPP) ; 132 | } 133 | 134 | rule AvrObject 135 | { 136 | switch $(>:S) 137 | { 138 | case .c : AvrCc $(<) : $(>) ; 139 | case .cpp : AvrC++ $(<) : $(>) ; 140 | case .pde : AvrPde $(<) : $(>) ; 141 | } 142 | } 143 | 144 | rule AvrObjects 145 | { 146 | for _I in $(<) 147 | { 148 | AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; 149 | } 150 | } 151 | 152 | rule AvrMainFromObjects 153 | { 154 | Depends $(<) : $(>) ; 155 | Depends $(<) : $(<:D) ; 156 | MkDir $(<:D) ; 157 | Depends all : $(<) ; 158 | Clean clean : $(<) ; 159 | } 160 | 161 | actions AvrMainFromObjects 162 | { 163 | $(AVR_LD) $(LDFLAGS) -o $(<) $(>) 164 | } 165 | 166 | rule AvrMain 167 | { 168 | AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; 169 | AvrObjects $(>) ; 170 | } 171 | 172 | rule AvrHex 173 | { 174 | Depends $(<) : $(>) ; 175 | Depends $(<) : $(<:D) ; 176 | Depends hex : $(<) ; 177 | Clean clean : $(<) ; 178 | } 179 | 180 | actions AvrHex 181 | { 182 | $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) 183 | } 184 | 185 | rule AvrUpload 186 | { 187 | Depends $(1) : $(2) ; 188 | Depends $(2) : $(3) ; 189 | NotFile $(1) ; 190 | Always $(1) ; 191 | Always $(2) ; 192 | AvrUploadAction $(2) : $(3) ; 193 | } 194 | 195 | actions AvrUploadAction 196 | { 197 | $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 198 | } 199 | 200 | AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; 201 | AvrHex $(OUT).hex : $(OUT).elf ; 202 | 203 | AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; 204 | AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; 205 | AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; 206 | 207 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/pingpair_multi_dyn/Jamfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = $(PWD:B) ; 2 | PROJECT_DIR = . ; 3 | PROJECT_LIBS = SPI RF24 ; 4 | 5 | OUT_DIR = ojam ; 6 | F_CPU = 16000000 ; 7 | MCU = atmega328p ; 8 | PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; 9 | 10 | UPLOAD_RATE = 57600 ; 11 | AVRDUDE_PROTOCOL = stk500v1 ; 12 | COM = 33 ; 13 | 14 | # Host-specific overrides for locations 15 | if $(OS) = MACOSX 16 | { 17 | ARDUINO_VERSION = 22 ; 18 | OLD_DIR = /opt/arduino-0021 ; 19 | AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; 20 | AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; 21 | ARDUINO_DIR = /opt/Arduino ; 22 | ARDUINO_AVR = /usr/lib/avr/include ; 23 | } 24 | 25 | # Where is everything? 26 | ARDUINO_VERSION ?= 22 ; 27 | AVR_TOOLS_PATH ?= /usr/bin ; 28 | ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; 29 | ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; 30 | AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; 31 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ; 32 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 33 | SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; 34 | AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; 35 | AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; 36 | AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; 37 | AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; 38 | AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; 39 | 40 | DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; 41 | CTUNING = -ffunction-sections -fdata-sections ; 42 | CXXTUNING = -fno-exceptions -fno-strict-aliasing ; 43 | CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ; 44 | CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; 45 | LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; 46 | 47 | # Search everywhere for headers 48 | HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; 49 | 50 | # Grab everything from the core directory 51 | CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 52 | 53 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 54 | # can specify specific modules to pick up in PROJECT_MODULES 55 | LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ; 56 | 57 | # In addition to explicitly-specified program modules, pick up anything from the current 58 | # dir. 59 | PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; 60 | 61 | # Shortcut for the out files 62 | OUT = $(OUT_DIR)/$(PROJECT_NAME) ; 63 | 64 | # AvrDude setup 65 | AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; 66 | 67 | rule GitVersion 68 | { 69 | Always $(<) ; 70 | Depends all : $(<) ; 71 | } 72 | 73 | actions GitVersion 74 | { 75 | echo "const char program_version[] = \"\\" > $(<) 76 | git log -1 --pretty=format:%h >> $(<) 77 | echo "\";" >> $(<) 78 | } 79 | 80 | GitVersion version.h ; 81 | 82 | rule AvrCc 83 | { 84 | Depends $(<) : $(>) ; 85 | Depends $(<) : $(<:D) ; 86 | Clean clean : $(<) ; 87 | 88 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 89 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 90 | } 91 | 92 | actions AvrCc 93 | { 94 | $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) 95 | } 96 | 97 | rule AvrC++ 98 | { 99 | Depends $(<) : $(>) ; 100 | Depends $(<) : $(<:D) ; 101 | Clean clean : $(<) ; 102 | 103 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 104 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 105 | } 106 | 107 | actions AvrC++ 108 | { 109 | $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) 110 | } 111 | 112 | rule Pde 113 | { 114 | Depends $(<) : $(>) ; 115 | Depends $(<) : $(<:D) ; 116 | Clean clean : $(<) ; 117 | 118 | } 119 | 120 | actions Pde 121 | { 122 | echo "#include " > $(<) 123 | echo "#line 1 \"$(>)\"" >> $(<) 124 | cat $(>) >> $(<) 125 | } 126 | 127 | rule AvrPde 128 | { 129 | local _CPP = $(OUT_DIR)/$(_I:B).cpp ; 130 | Pde $(_CPP) : $(>) ; 131 | AvrC++ $(<) : $(_CPP) ; 132 | } 133 | 134 | rule AvrObject 135 | { 136 | switch $(>:S) 137 | { 138 | case .c : AvrCc $(<) : $(>) ; 139 | case .cpp : AvrC++ $(<) : $(>) ; 140 | case .pde : AvrPde $(<) : $(>) ; 141 | } 142 | } 143 | 144 | rule AvrObjects 145 | { 146 | for _I in $(<) 147 | { 148 | AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; 149 | } 150 | } 151 | 152 | rule AvrMainFromObjects 153 | { 154 | Depends $(<) : $(>) ; 155 | Depends $(<) : $(<:D) ; 156 | MkDir $(<:D) ; 157 | Depends all : $(<) ; 158 | Clean clean : $(<) ; 159 | } 160 | 161 | actions AvrMainFromObjects 162 | { 163 | $(AVR_LD) $(LDFLAGS) -o $(<) $(>) 164 | } 165 | 166 | rule AvrMain 167 | { 168 | AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; 169 | AvrObjects $(>) ; 170 | } 171 | 172 | rule AvrHex 173 | { 174 | Depends $(<) : $(>) ; 175 | Depends $(<) : $(<:D) ; 176 | Depends hex : $(<) ; 177 | Clean clean : $(<) ; 178 | } 179 | 180 | actions AvrHex 181 | { 182 | $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) 183 | } 184 | 185 | rule AvrUpload 186 | { 187 | Depends $(1) : $(2) ; 188 | Depends $(2) : $(3) ; 189 | NotFile $(1) ; 190 | Always $(1) ; 191 | Always $(2) ; 192 | AvrUploadAction $(2) : $(3) ; 193 | } 194 | 195 | actions AvrUploadAction 196 | { 197 | $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 198 | } 199 | 200 | AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; 201 | AvrHex $(OUT).hex : $(OUT).elf ; 202 | 203 | AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; 204 | AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; 205 | AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; 206 | 207 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/starping/Jamfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = $(PWD:B) ; 2 | PROJECT_DIR = . ; 3 | PROJECT_LIBS = EEPROM SPI RF24 ; 4 | 5 | OUT_DIR = ojam ; 6 | F_CPU = 16000000 ; 7 | MCU = atmega328p ; 8 | PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; 9 | 10 | UPLOAD_RATE = 57600 ; 11 | AVRDUDE_PROTOCOL = stk500v1 ; 12 | COM = 33 ; 13 | 14 | # Host-specific overrides for locations 15 | if $(OS) = MACOSX 16 | { 17 | ARDUINO_VERSION = 22 ; 18 | OLD_DIR = /opt/arduino-0021 ; 19 | AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; 20 | AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; 21 | ARDUINO_DIR = /opt/Arduino ; 22 | ARDUINO_AVR = /usr/lib/avr/include ; 23 | } 24 | 25 | # Where is everything? 26 | ARDUINO_VERSION ?= 22 ; 27 | AVR_TOOLS_PATH ?= /usr/bin ; 28 | ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; 29 | ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; 30 | AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; 31 | ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ; 32 | ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; 33 | SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; 34 | AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; 35 | AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; 36 | AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; 37 | AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; 38 | AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; 39 | 40 | DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; 41 | CTUNING = -ffunction-sections -fdata-sections ; 42 | CXXTUNING = -fno-exceptions -fno-strict-aliasing ; 43 | CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ; 44 | CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; 45 | LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; 46 | 47 | # Search everywhere for headers 48 | HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; 49 | 50 | # Grab everything from the core directory 51 | CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; 52 | 53 | # Grab everything from libraries. To avoid this "grab everything" behaviour, you 54 | # can specify specific modules to pick up in PROJECT_MODULES 55 | LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ; 56 | 57 | # In addition to explicitly-specified program modules, pick up anything from the current 58 | # dir. 59 | PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; 60 | 61 | # Shortcut for the out files 62 | OUT = $(OUT_DIR)/$(PROJECT_NAME) ; 63 | 64 | # AvrDude setup 65 | AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; 66 | 67 | rule GitVersion 68 | { 69 | Always $(<) ; 70 | Depends all : $(<) ; 71 | } 72 | 73 | actions GitVersion 74 | { 75 | echo "const char program_version[] = \"\\" > $(<) 76 | git log -1 --pretty=format:%h >> $(<) 77 | echo "\";" >> $(<) 78 | } 79 | 80 | GitVersion version.h ; 81 | 82 | rule AvrCc 83 | { 84 | Depends $(<) : $(>) ; 85 | Depends $(<) : $(<:D) ; 86 | Clean clean : $(<) ; 87 | 88 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 89 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 90 | } 91 | 92 | actions AvrCc 93 | { 94 | $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) 95 | } 96 | 97 | rule AvrC++ 98 | { 99 | Depends $(<) : $(>) ; 100 | Depends $(<) : $(<:D) ; 101 | Clean clean : $(<) ; 102 | 103 | CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; 104 | CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 105 | } 106 | 107 | actions AvrC++ 108 | { 109 | $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) 110 | } 111 | 112 | rule Pde 113 | { 114 | Depends $(<) : $(>) ; 115 | Depends $(<) : $(<:D) ; 116 | Clean clean : $(<) ; 117 | 118 | } 119 | 120 | actions Pde 121 | { 122 | echo "#include " > $(<) 123 | echo "#line 1 \"$(>)\"" >> $(<) 124 | cat $(>) >> $(<) 125 | } 126 | 127 | rule AvrPde 128 | { 129 | local _CPP = $(OUT_DIR)/$(_I:B).cpp ; 130 | Pde $(_CPP) : $(>) ; 131 | AvrC++ $(<) : $(_CPP) ; 132 | } 133 | 134 | rule AvrObject 135 | { 136 | switch $(>:S) 137 | { 138 | case .c : AvrCc $(<) : $(>) ; 139 | case .cpp : AvrC++ $(<) : $(>) ; 140 | case .pde : AvrPde $(<) : $(>) ; 141 | } 142 | } 143 | 144 | rule AvrObjects 145 | { 146 | for _I in $(<) 147 | { 148 | AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; 149 | } 150 | } 151 | 152 | rule AvrMainFromObjects 153 | { 154 | Depends $(<) : $(>) ; 155 | Depends $(<) : $(<:D) ; 156 | MkDir $(<:D) ; 157 | Depends all : $(<) ; 158 | Clean clean : $(<) ; 159 | } 160 | 161 | actions AvrMainFromObjects 162 | { 163 | $(AVR_LD) $(LDFLAGS) -o $(<) $(>) 164 | } 165 | 166 | rule AvrMain 167 | { 168 | AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; 169 | AvrObjects $(>) ; 170 | } 171 | 172 | rule AvrHex 173 | { 174 | Depends $(<) : $(>) ; 175 | Depends $(<) : $(<:D) ; 176 | Depends hex : $(<) ; 177 | Clean clean : $(<) ; 178 | } 179 | 180 | actions AvrHex 181 | { 182 | $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) 183 | } 184 | 185 | rule AvrUpload 186 | { 187 | Depends $(1) : $(2) ; 188 | Depends $(2) : $(3) ; 189 | NotFile $(1) ; 190 | Always $(1) ; 191 | Always $(2) ; 192 | AvrUploadAction $(2) : $(3) ; 193 | } 194 | 195 | actions AvrUploadAction 196 | { 197 | $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i 198 | } 199 | 200 | AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; 201 | AvrHex $(OUT).hex : $(OUT).elf ; 202 | 203 | AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; 204 | AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; 205 | AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; 206 | 207 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/Transfer/Transfer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | TMRh20 2014 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** General Data Transfer Rate Test 10 | * This example demonstrates basic data transfer functionality with the 11 | updated library. This example will display the transfer rates acheived using 12 | the slower form of high-speed transfer using blocking-writes. 13 | */ 14 | 15 | 16 | #include 17 | #include "RF24.h" 18 | #include "printf.h" 19 | 20 | /************* USER Configuration *****************************/ 21 | // Hardware configuration 22 | RF24 radio(8,9); // Set up nRF24L01 radio on SPI bus plus pins 8 & 9 23 | 24 | /***************************************************************/ 25 | 26 | const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL }; // Radio pipe addresses for the 2 nodes to communicate. 27 | 28 | byte data[32]; //Data buffer for testing data transfer speeds 29 | 30 | unsigned long counter, rxTimer; //Counter and timer for keeping track transfer info 31 | unsigned long startTime, stopTime; 32 | bool TX=1,RX=0,role=0; 33 | 34 | void setup(void) { 35 | 36 | // The UNO Adapter uses pin 10 as Vcc 37 | pinMode(10,OUTPUT); 38 | digitalWrite(10,HIGH); 39 | delay(500); 40 | 41 | Serial.begin(57600); 42 | printf_begin(); 43 | 44 | radio.begin(); // Setup and configure rf radio 45 | radio.setChannel(1); 46 | radio.setPALevel(RF24_PA_MAX); 47 | radio.setDataRate(RF24_1MBPS); 48 | radio.setAutoAck(1); // Ensure autoACK is enabled 49 | radio.setRetries(2,15); // Optionally, increase the delay between retries & # of retries 50 | radio.setCRCLength(RF24_CRC_8); 51 | radio.openWritingPipe(pipes[0]); 52 | radio.openReadingPipe(1,pipes[1]); 53 | 54 | radio.startListening(); // Start listening 55 | radio.printDetails(); // Dump the configuration of the rf unit for debugging 56 | 57 | printf("\n\rRF24/examples/Transfer Rates/\n\r"); 58 | printf("*** PRESS 'T' to begin transmitting to the other node\n\r"); 59 | 60 | randomSeed(analogRead(0)); //Seed for random number generation 61 | 62 | for(int i=0; i<32; i++){ 63 | data[i] = random(255); //Load the buffer with random data 64 | } 65 | radio.powerUp(); //Power up the radio 66 | } 67 | 68 | void loop(void){ 69 | 70 | 71 | if(role == TX){ 72 | 73 | delay(2000); 74 | 75 | printf("Initiating Basic Data Transfer\n\r"); 76 | 77 | 78 | unsigned long cycles = 10000; //Change this to a higher or lower number. 79 | 80 | startTime = millis(); 81 | unsigned long pauseTime = millis(); 82 | 83 | for(int i=0; i 3){ 91 | // pauseTime = millis(); 92 | // radio.txStandBy(); // Need to drop out of TX mode every 4ms if sending a steady stream of multicast data 93 | // //delayMicroseconds(130); // This gives the PLL time to sync back up 94 | // } 95 | 96 | } 97 | 98 | stopTime = millis(); 99 | //This should be called to wait for completion and put the radio in standby mode after transmission, returns 0 if data still in FIFO (timed out), 1 if success 100 | if(!radio.txStandBy()){ counter+=3; } //Standby, block only until FIFO empty or auto-retry timeout. Flush TX FIFO if failed 101 | //radio.txStandBy(1000); //Standby, using extended timeout period of 1 second 102 | 103 | float numBytes = cycles*32; 104 | float rate = numBytes / (stopTime - startTime); 105 | 106 | Serial.print("Transfer complete at "); Serial.print(rate); printf(" KB/s \n\r"); 107 | Serial.print(counter); Serial.print(" of "); Serial.print(cycles); printf(" Packets Failed to Send\n\r"); 108 | counter = 0; 109 | 110 | } 111 | 112 | 113 | 114 | if(role == RX){ 115 | while(radio.available()){ 116 | radio.read(&data,32); 117 | counter++; 118 | } 119 | if(millis() - rxTimer > 1000){ 120 | rxTimer = millis(); 121 | float numBytes = (counter*32)/1000.0; 122 | Serial.print("Rate: "); 123 | Serial.print(numBytes); 124 | printf("KB/s \n Payload Count: %d \n\r", counter); 125 | counter = 0; 126 | } 127 | } 128 | // 129 | // Change roles 130 | // 131 | 132 | if ( Serial.available() ) 133 | { 134 | char c = toupper(Serial.read()); 135 | if ( c == 'T' && role == RX ) 136 | { 137 | printf("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK\n\r"); 138 | radio.openWritingPipe(pipes[1]); 139 | radio.openReadingPipe(1,pipes[0]); 140 | radio.stopListening(); 141 | role = TX; // Become the primary transmitter (ping out) 142 | } 143 | else if ( c == 'R' && role == TX ) 144 | { 145 | radio.openWritingPipe(pipes[0]); 146 | radio.openReadingPipe(1,pipes[1]); 147 | radio.startListening(); 148 | printf("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK\n\r"); 149 | role = RX; // Become the primary receiver (pong back) 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /С обратной связью и защитой связи/pyroTX/pyroTX.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Created 2017 3 | by AlexGyver 4 | AlexGyver Home Labs Inc. 5 | */ 6 | #include "Keypad.h" //библиотека клавиатуры 7 | #include // библиотека для работы с шиной SPI 8 | #include "nRF24L01.h" // библиотека радиомодуля 9 | #include "RF24.h" // ещё библиотека радиомодуля 10 | 11 | RF24 radio(9, 10); // "создать" модуль на пинах 9 и 10 Для Уно 12 | byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"}; //возможные номера труб 13 | 14 | byte redLED = 14; 15 | byte greenLED = 15; 16 | 17 | byte crypt_key = 123; // уникальный ключ для защиты связи 18 | int check = 111; // условный код, для обратной связи 19 | byte transm_data[2]; // массив отправляемых данных (уникальный ключ + код кнопки) 20 | boolean check_answer; 21 | 22 | const byte ROWS = 4; //4 строки у клавиатуры 23 | const byte COLS = 3; //три столбца 24 | char keys[4][3] = { 25 | {'1', '2', '3'}, 26 | {'4', '5', '6'}, 27 | {'7', '8', '9'}, 28 | {'*', '0', '#'} 29 | }; 30 | byte rowPins[ROWS] = {8, 7, 6, 5}; //Подключены строки (4 пина) 31 | byte colPins[COLS] = {4, 3, 2}; //подключены столбцы (3 пина) 32 | Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); //создать клавиатуру 33 | boolean flag; 34 | 35 | void setup() { 36 | Serial.begin(9600); 37 | 38 | transm_data[0] = crypt_key; // задать уникальный ключ для защиты связи 39 | 40 | pinMode(redLED, OUTPUT); 41 | pinMode(greenLED, OUTPUT); 42 | digitalWrite(greenLED, HIGH); // зажечь зелёный светодиод 43 | 44 | radio.begin(); //активировать модуль 45 | radio.setAutoAck(1); //режим подтверждения приёма, 1 вкл 0 выкл 46 | radio.setRetries(0, 15); //(время между попыткой достучаться, число попыток) 47 | radio.enableAckPayload(); //разрешить отсылку данных в ответ на входящий сигнал 48 | radio.setPayloadSize(32); //размер пакета, в байтах 49 | 50 | radio.openWritingPipe(address[0]); //мы - труба 0, открываем канал для передачи данных 51 | radio.setChannel(0x60); //выбираем канал (в котором нет шумов!) 52 | 53 | radio.setPALevel (RF24_PA_MAX); //уровень мощности передатчика. На выбор RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX 54 | radio.setDataRate (RF24_1MBPS); //скорость обмена. На выбор RF24_2MBPS, RF24_1MBPS, RF24_250KBPS 55 | //должна быть одинакова на приёмнике и передатчике! 56 | //при самой низкой скорости имеем самую высокую чувствительность и дальность!! 57 | 58 | radio.powerUp(); //начать работу 59 | radio.stopListening(); //не слушаем радиоэфир, мы передатчик 60 | } 61 | 62 | void loop() { 63 | byte gotByte; 64 | char key = keypad.waitForKey(); // ожидать ввод с клавиатуры, принять символ 65 | int keyInt = key - '0'; // перевести символ в целочисленный тип 66 | 67 | if (keyInt >= 0 && keyInt <= 9 && flag == 1) { // если число от 0 до 9 и флаг поднят 68 | digitalWrite(greenLED, HIGH); // включить зелёный светодиод 69 | digitalWrite(redLED, LOW); // погасить красный светодиод 70 | transm_data[1] = keyInt; // на второе место массива ставим нажатую кнопку 71 | radio.write(&transm_data, sizeof(transm_data)); // отправить массив по радио 72 | delay(10); 73 | digitalWrite(greenLED, LOW); // погасить зелёный светодиод 74 | digitalWrite(redLED, HIGH); // зажечь красный светодиод 75 | 76 | } else if (key == '*') { // если символ * 77 | flag = 0; // опустить флаг 78 | 79 | digitalWrite(redLED, LOW); // погасить красный светодиод 80 | digitalWrite(greenLED, LOW); // погасить зелёный светодиод 81 | delay(100); // задержка для эпичности 82 | 83 | transm_data[1] = check; // на второе место массива ставим условный код для проверки 84 | if ( radio.write(&transm_data, sizeof(transm_data)) ) { // отправляем 85 | if (!radio.available()) { // если не получаем ответ 86 | Serial.println("No answer"); 87 | digitalWrite(greenLED, HIGH); // включить зелёный светодиод 88 | } else { 89 | while (radio.available() ) { // если в ответе что-то есть 90 | radio.read( &check_answer, 1); // читаем 91 | if (check_answer == 1) { // если статус = 1 (готов к работе) 92 | flag = 1; // поднять флаг готовности к работе 93 | digitalWrite(redLED, HIGH); // зажечь красный светодиод 94 | Serial.println("Status OK"); 95 | } else { // если статус = 0 (акум разряжен) 96 | Serial.println("Status BAD"); 97 | for (int i = 0; i < 5; i++) { // моргнуть 6 раз зелёным светодиодом 98 | digitalWrite(greenLED, HIGH); 99 | delay(200); 100 | digitalWrite(greenLED, LOW); 101 | delay(100); 102 | } 103 | digitalWrite(greenLED, HIGH); // включить зелёный светодиод при ошибке 104 | } 105 | } 106 | } 107 | } else { 108 | Serial.println("Sending failed"); // ошибка отправки 109 | digitalWrite(greenLED, HIGH); // включить зелёный светодиод 110 | } 111 | 112 | } else if (key == '#') { // если символ № 113 | flag = 0; // опустить флаг 114 | digitalWrite(greenLED, HIGH); // зажечь зелёный светодиод 115 | digitalWrite(redLED, LOW); // погасить красный светодиод 116 | } 117 | } 118 | 119 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/GettingStarted/GettingStarted.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | //2014 - TMRh20 - Updated along with Optimized RF24 Library fork 8 | */ 9 | 10 | /** 11 | * Example for Getting Started with nRF24L01+ radios. 12 | * 13 | * This is an example of how to use the RF24 class to communicate on a basic level. Write this sketch to two 14 | * different nodes. Put one of the nodes into 'transmit' mode by connecting with the serial monitor and 15 | * sending a 'T'. The ping node sends the current time to the pong node, which responds by sending the value 16 | * back. The ping node can then see how long the whole cycle took. 17 | * Note: For a more efficient call-response scenario see the GettingStarted_CallResponse.ino example. 18 | * Note: When switching between sketches, the radio may need to be powered down to clear settings that are not "un-set" otherwise 19 | */ 20 | 21 | 22 | #include 23 | #include "nRF24L01.h" 24 | #include "RF24.h" 25 | #include "printf.h" 26 | 27 | // Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 9 & 10 28 | RF24 radio(7,8); 29 | 30 | byte addresses[][6] = {"1Node","2Node"}; 31 | 32 | 33 | // Set up roles to simplify testing 34 | boolean role; // The main role variable, holds the current role identifier 35 | boolean role_ping_out = 1, role_pong_back = 0; // The two different roles. 36 | 37 | void setup() { 38 | 39 | 40 | Serial.begin(57600); 41 | printf_begin(); 42 | printf("\n\rRF24/examples/GettingStarted/\n\r"); 43 | printf("*** PRESS 'T' to begin transmitting to the other node\n\r"); 44 | 45 | // Setup and configure rf radio 46 | radio.begin(); // Start up the radio 47 | radio.setAutoAck(1); // Ensure autoACK is enabled 48 | radio.setRetries(15,15); // Max delay between retries & number of retries 49 | radio.openWritingPipe(addresses[1]); 50 | radio.openReadingPipe(1,addresses[0]); 51 | 52 | radio.startListening(); // Start listening 53 | radio.printDetails(); // Dump the configuration of the rf unit for debugging 54 | } 55 | 56 | void loop(void){ 57 | 58 | 59 | /****************** Ping Out Role ***************************/ 60 | if (role == role_ping_out) { 61 | 62 | radio.stopListening(); // First, stop listening so we can talk. 63 | 64 | 65 | printf("Now sending \n\r"); 66 | 67 | unsigned long time = micros(); // Take the time, and send it. This will block until complete 68 | if (!radio.write( &time, sizeof(unsigned long) )){ printf("failed.\n\r"); } 69 | 70 | radio.startListening(); // Now, continue listening 71 | 72 | unsigned long started_waiting_at = micros(); // Set up a timeout period, get the current microseconds 73 | boolean timeout = false; // Set up a variable to indicate if a response was received or not 74 | 75 | while ( ! radio.available() ){ // While nothing is received 76 | if (micros() - started_waiting_at > 200000 ){ // If waited longer than 200ms, indicate timeout and exit while loop 77 | timeout = true; 78 | break; 79 | } 80 | } 81 | 82 | if ( timeout ){ // Describe the results 83 | printf("Failed, response timed out.\n\r"); 84 | }else{ 85 | unsigned long got_time; // Grab the response, compare, and send to debugging spew 86 | radio.read( &got_time, sizeof(unsigned long) ); 87 | 88 | // Spew it 89 | printf("Sent %lu, Got response %lu, round-trip delay: %lu microseconds\n\r",time,got_time,micros()-got_time); 90 | } 91 | 92 | // Try again 1s later 93 | delay(1000); 94 | } 95 | 96 | /****************** Pong Back Role ***************************/ 97 | 98 | if ( role == role_pong_back ) 99 | { 100 | if( radio.available()){ 101 | unsigned long got_time; // Variable for the received timestamp 102 | while (radio.available()) { // While there is data ready 103 | radio.read( &got_time, sizeof(unsigned long) ); // Get the payload 104 | } 105 | 106 | radio.stopListening(); // First, stop listening so we can talk 107 | radio.write( &got_time, sizeof(unsigned long) ); // Send the final one back. 108 | radio.startListening(); // Now, resume listening so we catch the next packets. 109 | printf("Sent response %lu \n\r", got_time); 110 | } 111 | } 112 | 113 | 114 | /****************** Change Roles via Serial Commands ***************************/ 115 | 116 | if ( Serial.available() ) 117 | { 118 | char c = toupper(Serial.read()); 119 | if ( c == 'T' && role == role_pong_back ) 120 | { 121 | printf("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK\n\r"); 122 | 123 | role = role_ping_out; // Become the primary transmitter (ping out) 124 | radio.openWritingPipe(addresses[0]); 125 | radio.openReadingPipe(1,addresses[1]); 126 | 127 | } 128 | else if ( c == 'R' && role == role_ping_out ) 129 | { 130 | printf("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK\n\r"); 131 | 132 | role = role_pong_back; // Become the primary receiver (pong back) 133 | radio.openWritingPipe(addresses[1]); 134 | radio.openReadingPipe(1,addresses[0]); 135 | } 136 | } 137 | } -------------------------------------------------------------------------------- /Библиотеки/Keypad-master/src/Keypad.h: -------------------------------------------------------------------------------- 1 | /* 2 | || 3 | || @file Keypad.h 4 | || @version 3.1 5 | || @author Mark Stanley, Alexander Brevig 6 | || @contact mstanley@technologist.com, alexanderbrevig@gmail.com 7 | || 8 | || @description 9 | || | This library provides a simple interface for using matrix 10 | || | keypads. It supports multiple keypresses while maintaining 11 | || | backwards compatibility with the old single key library. 12 | || | It also supports user selectable pins and definable keymaps. 13 | || # 14 | || 15 | || @license 16 | || | This library is free software; you can redistribute it and/or 17 | || | modify it under the terms of the GNU Lesser General Public 18 | || | License as published by the Free Software Foundation; version 19 | || | 2.1 of the License. 20 | || | 21 | || | This library is distributed in the hope that it will be useful, 22 | || | but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | || | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | || | Lesser General Public License for more details. 25 | || | 26 | || | You should have received a copy of the GNU Lesser General Public 27 | || | License along with this library; if not, write to the Free Software 28 | || | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 29 | || # 30 | || 31 | */ 32 | 33 | #ifndef KEYPAD_H 34 | #define KEYPAD_H 35 | 36 | #include "Key.h" 37 | 38 | // bperrybap - Thanks for a well reasoned argument and the following macro(s). 39 | // See http://arduino.cc/forum/index.php/topic,142041.msg1069480.html#msg1069480 40 | #ifndef INPUT_PULLUP 41 | #warning "Using pinMode() INPUT_PULLUP AVR emulation" 42 | #define INPUT_PULLUP 0x2 43 | #define pinMode(_pin, _mode) _mypinMode(_pin, _mode) 44 | #define _mypinMode(_pin, _mode) \ 45 | do { \ 46 | if(_mode == INPUT_PULLUP) \ 47 | pinMode(_pin, INPUT); \ 48 | digitalWrite(_pin, 1); \ 49 | if(_mode != INPUT_PULLUP) \ 50 | pinMode(_pin, _mode); \ 51 | }while(0) 52 | #endif 53 | 54 | 55 | #define OPEN LOW 56 | #define CLOSED HIGH 57 | 58 | typedef char KeypadEvent; 59 | typedef unsigned int uint; 60 | typedef unsigned long ulong; 61 | 62 | // Made changes according to this post http://arduino.cc/forum/index.php?topic=58337.0 63 | // by Nick Gammon. Thanks for the input Nick. It actually saved 78 bytes for me. :) 64 | typedef struct { 65 | byte rows; 66 | byte columns; 67 | } KeypadSize; 68 | 69 | #define LIST_MAX 10 // Max number of keys on the active list. 70 | #define MAPSIZE 10 // MAPSIZE is the number of rows (times 16 columns) 71 | #define makeKeymap(x) ((char*)x) 72 | 73 | 74 | //class Keypad : public Key, public HAL_obj { 75 | class Keypad : public Key { 76 | public: 77 | 78 | Keypad(char *userKeymap, byte *row, byte *col, byte numRows, byte numCols); 79 | 80 | virtual void pin_mode(byte pinNum, byte mode) { pinMode(pinNum, mode); } 81 | virtual void pin_write(byte pinNum, boolean level) { digitalWrite(pinNum, level); } 82 | virtual int pin_read(byte pinNum) { return digitalRead(pinNum); } 83 | 84 | uint bitMap[MAPSIZE]; // 10 row x 16 column array of bits. Except Due which has 32 columns. 85 | Key key[LIST_MAX]; 86 | unsigned long holdTimer; 87 | 88 | char getKey(); 89 | bool getKeys(); 90 | KeyState getState(); 91 | void begin(char *userKeymap); 92 | bool isPressed(char keyChar); 93 | void setDebounceTime(uint); 94 | void setHoldTime(uint); 95 | void addEventListener(void (*listener)(char)); 96 | int findInList(char keyChar); 97 | int findInList(int keyCode); 98 | char waitForKey(); 99 | bool keyStateChanged(); 100 | byte numKeys(); 101 | 102 | private: 103 | unsigned long startTime; 104 | char *keymap; 105 | byte *rowPins; 106 | byte *columnPins; 107 | KeypadSize sizeKpd; 108 | uint debounceTime; 109 | uint holdTime; 110 | bool single_key; 111 | 112 | void scanKeys(); 113 | bool updateList(); 114 | void nextKeyState(byte n, boolean button); 115 | void transitionTo(byte n, KeyState nextState); 116 | void (*keypadEventListener)(char); 117 | }; 118 | 119 | #endif 120 | 121 | /* 122 | || @changelog 123 | || | 3.1 2013-01-15 - Mark Stanley : Fixed missing RELEASED & IDLE status when using a single key. 124 | || | 3.0 2012-07-12 - Mark Stanley : Made library multi-keypress by default. (Backwards compatible) 125 | || | 3.0 2012-07-12 - Mark Stanley : Modified pin functions to support Keypad_I2C 126 | || | 3.0 2012-07-12 - Stanley & Young : Removed static variables. Fix for multiple keypad objects. 127 | || | 3.0 2012-07-12 - Mark Stanley : Fixed bug that caused shorted pins when pressing multiple keys. 128 | || | 2.0 2011-12-29 - Mark Stanley : Added waitForKey(). 129 | || | 2.0 2011-12-23 - Mark Stanley : Added the public function keyStateChanged(). 130 | || | 2.0 2011-12-23 - Mark Stanley : Added the private function scanKeys(). 131 | || | 2.0 2011-12-23 - Mark Stanley : Moved the Finite State Machine into the function getKeyState(). 132 | || | 2.0 2011-12-23 - Mark Stanley : Removed the member variable lastUdate. Not needed after rewrite. 133 | || | 1.8 2011-11-21 - Mark Stanley : Added test to determine which header file to compile, 134 | || | WProgram.h or Arduino.h. 135 | || | 1.8 2009-07-08 - Alexander Brevig : No longer uses arrays 136 | || | 1.7 2009-06-18 - Alexander Brevig : This library is a Finite State Machine every time a state changes 137 | || | the keypadEventListener will trigger, if set 138 | || | 1.7 2009-06-18 - Alexander Brevig : Added setDebounceTime setHoldTime specifies the amount of 139 | || | microseconds before a HOLD state triggers 140 | || | 1.7 2009-06-18 - Alexander Brevig : Added transitionTo 141 | || | 1.6 2009-06-15 - Alexander Brevig : Added getState() and state variable 142 | || | 1.5 2009-05-19 - Alexander Brevig : Added setHoldTime() 143 | || | 1.4 2009-05-15 - Alexander Brevig : Added addEventListener 144 | || | 1.3 2009-05-12 - Alexander Brevig : Added lastUdate, in order to do simple debouncing 145 | || | 1.2 2009-05-09 - Alexander Brevig : Changed getKey() 146 | || | 1.1 2009-04-28 - Alexander Brevig : Modified API, and made variables private 147 | || | 1.0 2007-XX-XX - Mark Stanley : Initial Release 148 | || # 149 | */ 150 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/pingpair_irq/pingpair_irq.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | 8 | Update 2014 - TMRh20 9 | */ 10 | 11 | /** 12 | * Example of using interrupts 13 | * 14 | * This is an example of how to user interrupts to interact with the radio, and a demonstration 15 | * of how to use them to sleep when receiving, and not miss any payloads. 16 | * The pingpair_sleepy example expands on sleep functionality with a timed sleep option for the transmitter. 17 | * Sleep functionality is built directly into my fork of the RF24Network library 18 | */ 19 | 20 | #include 21 | #include "nRF24L01.h" 22 | #include "RF24.h" 23 | #include "printf.h" 24 | #include 25 | #include 26 | 27 | // Hardware configuration 28 | RF24 radio(7,8); // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 29 | 30 | const short role_pin = 5; // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver 31 | // Leave open to be the 'ping' transmitter 32 | 33 | const uint64_t address[2] = {0xABCDABCD71LL, 0x544d52687CLL}; // Radio pipe addresses for the 2 nodes to communicate. 34 | 35 | // Role management 36 | 37 | // Set up role. This sketch uses the same software for all the nodes in this 38 | // system. Doing so greatly simplifies testing. The hardware itself specifies 39 | // which node it is. 40 | // This is done through the role_pin 41 | typedef enum { role_sender = 1, role_receiver } role_e; // The various roles supported by this sketch 42 | const char* role_friendly_name[] = { "invalid", "Sender", "Receiver"}; // The debug-friendly names of those roles 43 | role_e role; // The role of the current running sketch 44 | 45 | boolean gotMsg = 0; // So we know when to go to sleep 46 | 47 | /********************** Setup *********************/ 48 | void setup(){ 49 | 50 | pinMode(role_pin, INPUT); // set up the role pin 51 | digitalWrite(role_pin,HIGH); // Change this to LOW/HIGH instead of using an external pin 52 | delay(20); // Just to get a solid reading on the role pin 53 | 54 | if ( digitalRead(role_pin) ) // read the address pin, establish our role 55 | role = role_sender; 56 | else 57 | role = role_receiver; 58 | 59 | 60 | Serial.begin(115200); 61 | printf_begin(); 62 | printf("\n\rRF24/examples/pingpair_irq/\n\r"); 63 | printf("ROLE: %s\n\r",role_friendly_name[role]); 64 | 65 | // Setup and configure rf radio 66 | radio.begin(); 67 | radio.enableAckPayload(); // We will be using the Ack Payload feature, so please enable it 68 | // Open pipes to other node for communication 69 | if ( role == role_sender ) { // This simple sketch opens a pipe on a single address for these two nodes to 70 | radio.openWritingPipe(address[0]); // communicate back and forth. One listens on it, the other talks to it. 71 | radio.openReadingPipe(1,address[1]); 72 | }else{ 73 | radio.openWritingPipe(address[1]); 74 | radio.openReadingPipe(1,address[0]); 75 | radio.startListening(); 76 | } 77 | radio.printDetails(); // Dump the configuration of the rf unit for debugging 78 | delay(50); 79 | attachInterrupt(0, check_radio, FALLING); // Attach interrupt handler to interrupt #0 (using pin 2) on BOTH the sender and receiver 80 | } 81 | 82 | static uint32_t message_count = 0; 83 | 84 | 85 | /********************** Main Loop *********************/ 86 | void loop() { 87 | 88 | 89 | if (role == role_sender) { // Sender role. Repeatedly send the current time 90 | unsigned long time = millis(); // Take the time, and send it. 91 | printf("Now sending %lu\n\r",time); 92 | radio.startWrite( &time, sizeof(unsigned long) ,0); 93 | delay(2000); // Try again soon 94 | } 95 | 96 | 97 | if(role == role_receiver){ // Receiver does nothing except in IRQ 98 | } 99 | } 100 | 101 | 102 | /********************** Interrupt *********************/ 103 | 104 | void check_radio(void) // Receiver role: Does nothing! All the work is in IRQ 105 | { 106 | 107 | bool tx,fail,rx; 108 | radio.whatHappened(tx,fail,rx); // What happened? 109 | 110 | if ( tx ) { // Have we successfully transmitted? 111 | if ( role == role_sender ){ printf("Send:OK\n\r"); } 112 | if ( role == role_receiver ){ printf("Ack Payload:Sent\n\r"); } 113 | } 114 | 115 | if ( fail ) { // Have we failed to transmit? 116 | if ( role == role_sender ){ printf("Send:Failed\n\r"); } 117 | if ( role == role_receiver ){ printf("Ack Payload:Failed\n\r"); } 118 | } 119 | 120 | if ( rx || radio.available()){ // Did we receive a message? 121 | 122 | if ( role == role_sender ) { // If we're the sender, we've received an ack payload 123 | radio.read(&message_count,sizeof(message_count)); 124 | printf("Ack:%lu\n\r",message_count); 125 | } 126 | 127 | 128 | if ( role == role_receiver ) { // If we're the receiver, we've received a time message 129 | static unsigned long got_time; // Get this payload and dump it 130 | radio.read( &got_time, sizeof(got_time) ); 131 | printf("Got payload %lu\n\r",got_time); 132 | radio.writeAckPayload( 1, &message_count, sizeof(message_count) ); // Add an ack packet for the next time around. This is a simple 133 | ++message_count; // packet counter 134 | 135 | } 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/Usage/led_remote/led_remote.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example LED Remote 11 | * 12 | * This is an example of how to use the RF24 class to control a remote 13 | * bank of LED's using buttons on a remote control. 14 | * 15 | * On the 'remote', connect any number of buttons or switches from 16 | * an arduino pin to ground. Update 'button_pins' to reflect the 17 | * pins used. 18 | * 19 | * On the 'led' board, connect the same number of LED's from an 20 | * arduino pin to a resistor to ground. Update 'led_pins' to reflect 21 | * the pins used. Also connect a separate pin to ground and change 22 | * the 'role_pin'. This tells the sketch it's running on the LED board. 23 | * 24 | * Every time the buttons change on the remote, the entire state of 25 | * buttons is send to the led board, which displays the state. 26 | */ 27 | 28 | #include 29 | #include "RF24.h" 30 | #include "printf.h" 31 | 32 | // 33 | // Hardware configuration 34 | // 35 | 36 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 37 | 38 | RF24 radio(9,10); 39 | 40 | // sets the role of this unit in hardware. Connect to GND to be the 'led' board receiver 41 | // Leave open to be the 'remote' transmitter 42 | const int role_pin = A4; 43 | 44 | // Pins on the remote for buttons 45 | const uint8_t button_pins[] = { 2,3,4,5,6,7 }; 46 | const uint8_t num_button_pins = sizeof(button_pins); 47 | 48 | // Pins on the LED board for LED's 49 | const uint8_t led_pins[] = { 2,3,4,5,6,7 }; 50 | const uint8_t num_led_pins = sizeof(led_pins); 51 | 52 | // 53 | // Topology 54 | // 55 | 56 | // Single radio pipe address for the 2 nodes to communicate. 57 | const uint64_t pipe = 0xE8E8F0F0E1LL; 58 | 59 | // 60 | // Role management 61 | // 62 | // Set up role. This sketch uses the same software for all the nodes in this 63 | // system. Doing so greatly simplifies testing. The hardware itself specifies 64 | // which node it is. 65 | // 66 | // This is done through the role_pin 67 | // 68 | 69 | // The various roles supported by this sketch 70 | typedef enum { role_remote = 1, role_led } role_e; 71 | 72 | // The debug-friendly names of those roles 73 | const char* role_friendly_name[] = { "invalid", "Remote", "LED Board"}; 74 | 75 | // The role of the current running sketch 76 | role_e role; 77 | 78 | // 79 | // Payload 80 | // 81 | 82 | uint8_t button_states[num_button_pins]; 83 | uint8_t led_states[num_led_pins]; 84 | 85 | // 86 | // Setup 87 | // 88 | 89 | void setup(void) 90 | { 91 | // 92 | // Role 93 | // 94 | 95 | // set up the role pin 96 | pinMode(role_pin, INPUT); 97 | digitalWrite(role_pin,HIGH); 98 | delay(20); // Just to get a solid reading on the role pin 99 | 100 | // read the address pin, establish our role 101 | if ( digitalRead(role_pin) ) 102 | role = role_remote; 103 | else 104 | role = role_led; 105 | 106 | // 107 | // Print preamble 108 | // 109 | 110 | Serial.begin(57600); 111 | printf_begin(); 112 | printf("\n\rRF24/examples/led_remote/\n\r"); 113 | printf("ROLE: %s\n\r",role_friendly_name[role]); 114 | 115 | // 116 | // Setup and configure rf radio 117 | // 118 | 119 | radio.begin(); 120 | 121 | // 122 | // Open pipes to other nodes for communication 123 | // 124 | 125 | // This simple sketch opens a single pipes for these two nodes to communicate 126 | // back and forth. One listens on it, the other talks to it. 127 | 128 | if ( role == role_remote ) 129 | { 130 | radio.openWritingPipe(pipe); 131 | } 132 | else 133 | { 134 | radio.openReadingPipe(1,pipe); 135 | } 136 | 137 | // 138 | // Start listening 139 | // 140 | 141 | if ( role == role_led ) 142 | radio.startListening(); 143 | 144 | // 145 | // Dump the configuration of the rf unit for debugging 146 | // 147 | 148 | radio.printDetails(); 149 | 150 | // 151 | // Set up buttons / LED's 152 | // 153 | 154 | // Set pull-up resistors for all buttons 155 | if ( role == role_remote ) 156 | { 157 | int i = num_button_pins; 158 | while(i--) 159 | { 160 | pinMode(button_pins[i],INPUT); 161 | digitalWrite(button_pins[i],HIGH); 162 | } 163 | } 164 | 165 | // Turn LED's ON until we start getting keys 166 | if ( role == role_led ) 167 | { 168 | int i = num_led_pins; 169 | while(i--) 170 | { 171 | pinMode(led_pins[i],OUTPUT); 172 | led_states[i] = HIGH; 173 | digitalWrite(led_pins[i],led_states[i]); 174 | } 175 | } 176 | 177 | } 178 | 179 | // 180 | // Loop 181 | // 182 | 183 | void loop(void) 184 | { 185 | // 186 | // Remote role. If the state of any button has changed, send the whole state of 187 | // all buttons. 188 | // 189 | 190 | if ( role == role_remote ) 191 | { 192 | // Get the current state of buttons, and 193 | // Test if the current state is different from the last state we sent 194 | int i = num_button_pins; 195 | bool different = false; 196 | while(i--) 197 | { 198 | uint8_t state = ! digitalRead(button_pins[i]); 199 | if ( state != button_states[i] ) 200 | { 201 | different = true; 202 | button_states[i] = state; 203 | } 204 | } 205 | 206 | // Send the state of the buttons to the LED board 207 | if ( different ) 208 | { 209 | printf("Now sending..."); 210 | bool ok = radio.write( button_states, num_button_pins ); 211 | if (ok) 212 | printf("ok\n\r"); 213 | else 214 | printf("failed\n\r"); 215 | } 216 | 217 | // Try again in a short while 218 | delay(20); 219 | } 220 | 221 | // 222 | // LED role. Receive the state of all buttons, and reflect that in the LEDs 223 | // 224 | 225 | if ( role == role_led ) 226 | { 227 | // if there is data ready 228 | if ( radio.available() ) 229 | { 230 | // Dump the payloads until we've gotten everything 231 | bool done = false; 232 | while (!done) 233 | { 234 | // Fetch the payload, and see if this was the last one. 235 | done = radio.read( button_states, num_button_pins ); 236 | 237 | // Spew it 238 | printf("Got buttons\n\r"); 239 | 240 | // For each button, if the button now on, then toggle the LED 241 | int i = num_led_pins; 242 | while(i--) 243 | { 244 | if ( button_states[i] ) 245 | { 246 | led_states[i] ^= HIGH; 247 | digitalWrite(led_pins[i],led_states[i]); 248 | } 249 | } 250 | } 251 | } 252 | } 253 | } 254 | // vim:ai:cin:sts=2 sw=2 ft=cpp 255 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/Usage/pingpair_maple/pingpair_maple.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example RF Radio Ping Pair ... for Maple 11 | * 12 | * This is an example of how to use the RF24 class. Write this sketch to two different nodes, 13 | * connect the role_pin to ground on one. The ping node sends the current time to the pong node, 14 | * which responds by sending the value back. The ping node can then see how long the whole cycle 15 | * took. 16 | */ 17 | 18 | #include "WProgram.h" 19 | #include 20 | #include "nRF24L01.h" 21 | #include "RF24.h" 22 | 23 | // 24 | // Maple specific setup. Other than this section, the sketch is the same on Maple as on 25 | // Arduino 26 | // 27 | 28 | #ifdef MAPLE_IDE 29 | 30 | // External startup function 31 | extern void board_start(const char* program_name); 32 | 33 | // Use SPI #2. 34 | HardwareSPI SPI(2); 35 | 36 | #else 37 | #define board_startup printf 38 | #define toggleLED(x) (x) 39 | #endif 40 | 41 | // 42 | // Hardware configuration 43 | // 44 | 45 | // Set up nRF24L01 radio on SPI bus plus pins 7 & 6 46 | // (This works for the Getting Started board plugged into the 47 | // Maple Native backwards.) 48 | 49 | RF24 radio(7,6); 50 | 51 | // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver 52 | // Leave open to be the 'ping' transmitter 53 | const int role_pin = 10; 54 | 55 | // 56 | // Topology 57 | // 58 | 59 | // Radio pipe addresses for the 2 nodes to communicate. 60 | const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; 61 | 62 | // 63 | // Role management 64 | // 65 | // Set up role. This sketch uses the same software for all the nodes 66 | // in this system. Doing so greatly simplifies testing. The hardware itself specifies 67 | // which node it is. 68 | // 69 | // This is done through the role_pin 70 | // 71 | 72 | // The various roles supported by this sketch 73 | typedef enum { role_ping_out = 1, role_pong_back } role_e; 74 | 75 | // The debug-friendly names of those roles 76 | const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; 77 | 78 | // The role of the current running sketch 79 | role_e role; 80 | 81 | void setup(void) 82 | { 83 | // 84 | // Role 85 | // 86 | 87 | // set up the role pin 88 | pinMode(role_pin, INPUT); 89 | digitalWrite(role_pin,HIGH); 90 | delay(20); // Just to get a solid reading on the role pin 91 | 92 | // read the address pin, establish our role 93 | if ( digitalRead(role_pin) ) 94 | role = role_ping_out; 95 | else 96 | role = role_pong_back; 97 | 98 | // 99 | // Print preamble 100 | // 101 | 102 | board_start("\n\rRF24/examples/pingpair/\n\r"); 103 | printf("ROLE: %s\n\r",role_friendly_name[role]); 104 | 105 | // 106 | // Setup and configure rf radio 107 | // 108 | 109 | radio.begin(); 110 | 111 | // optionally, increase the delay between retries & # of retries 112 | radio.setRetries(15,15); 113 | 114 | // optionally, reduce the payload size. seems to 115 | // improve reliability 116 | radio.setPayloadSize(8); 117 | 118 | // 119 | // Open pipes to other nodes for communication 120 | // 121 | 122 | // This simple sketch opens two pipes for these two nodes to communicate 123 | // back and forth. 124 | // Open 'our' pipe for writing 125 | // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) 126 | 127 | if ( role == role_ping_out ) 128 | { 129 | radio.openWritingPipe(pipes[0]); 130 | radio.openReadingPipe(1,pipes[1]); 131 | } 132 | else 133 | { 134 | radio.openWritingPipe(pipes[1]); 135 | radio.openReadingPipe(1,pipes[0]); 136 | } 137 | 138 | // 139 | // Start listening 140 | // 141 | 142 | radio.startListening(); 143 | 144 | // 145 | // Dump the configuration of the rf unit for debugging 146 | // 147 | 148 | radio.printDetails(); 149 | } 150 | 151 | void loop(void) 152 | { 153 | // 154 | // Ping out role. Repeatedly send the current time 155 | // 156 | 157 | if (role == role_ping_out) 158 | { 159 | toggleLED(); 160 | 161 | // First, stop listening so we can talk. 162 | radio.stopListening(); 163 | 164 | // Take the time, and send it. This will block until complete 165 | unsigned long time = millis(); 166 | printf("Now sending %lu...",time); 167 | bool ok = radio.write( &time, sizeof(unsigned long) ); 168 | 169 | if (ok) 170 | printf("ok...\r\n"); 171 | else 172 | printf("failed.\r\n"); 173 | 174 | // Now, continue listening 175 | radio.startListening(); 176 | 177 | // Wait here until we get a response, or timeout (250ms) 178 | unsigned long started_waiting_at = millis(); 179 | bool timeout = false; 180 | while ( ! radio.available() && ! timeout ) 181 | if (millis() - started_waiting_at > 200 ) 182 | timeout = true; 183 | 184 | // Describe the results 185 | if ( timeout ) 186 | { 187 | printf("Failed, response timed out.\r\n"); 188 | } 189 | else 190 | { 191 | // Grab the response, compare, and send to debugging spew 192 | unsigned long got_time; 193 | radio.read( &got_time, sizeof(unsigned long) ); 194 | 195 | // Spew it 196 | printf("Got response %lu, round-trip delay: %lu\r\n",got_time,millis()-got_time); 197 | } 198 | 199 | toggleLED(); 200 | 201 | // Try again 1s later 202 | delay(1000); 203 | } 204 | 205 | // 206 | // Pong back role. Receive each packet, dump it out, and send it back 207 | // 208 | 209 | if ( role == role_pong_back ) 210 | { 211 | // if there is data ready 212 | if ( radio.available() ) 213 | { 214 | // Dump the payloads until we've gotten everything 215 | unsigned long got_time; 216 | bool done = false; 217 | while (!done) 218 | { 219 | // Fetch the payload, and see if this was the last one. 220 | done = radio.read( &got_time, sizeof(unsigned long) ); 221 | 222 | // Spew it 223 | printf("Got payload %lu...",got_time); 224 | 225 | // Delay just a little bit to let the other unit 226 | // make the transition to receiver 227 | delay(20); 228 | } 229 | 230 | // First, stop listening so we can talk 231 | radio.stopListening(); 232 | 233 | // Send the final one back. 234 | radio.write( &got_time, sizeof(unsigned long) ); 235 | printf("Sent response.\r\n"); 236 | 237 | // Now, resume listening so we catch the next packets. 238 | radio.startListening(); 239 | } 240 | } 241 | } 242 | // vim:cin:ai:sts=2 sw=2 ft=cpp 243 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/pingpair_dyn/pingpair_dyn.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example using Dynamic Payloads 11 | * 12 | * This is an example of how to use payloads of a varying (dynamic) size. 13 | */ 14 | 15 | #include 16 | #include "RF24.h" 17 | #include "printf.h" 18 | 19 | // 20 | // Hardware configuration 21 | // 22 | 23 | // Set up nRF24L01 radio on SPI bus plus pins 24 | // CE = 8, CSN = 9 25 | RF24 radio(8,9); 26 | 27 | // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver 28 | // Leave open to be the 'ping' transmitter 29 | const int role_pin = 5; 30 | 31 | // 32 | // Topology 33 | // 34 | 35 | // Radio pipe addresses for the 2 nodes to communicate. 36 | const uint64_t pipes[2] = { 0xEEFDFDFDECLL, 0xEEFDFDF0DFLL }; 37 | 38 | // 39 | // Role management 40 | // 41 | // Set up role. This sketch uses the same software for all the nodes 42 | // in this system. Doing so greatly simplifies testing. The hardware itself specifies 43 | // which node it is. 44 | // 45 | // This is done through the role_pin 46 | // 47 | 48 | // The various roles supported by this sketch 49 | typedef enum { role_ping_out = 1, role_pong_back } role_e; 50 | 51 | // The debug-friendly names of those roles 52 | const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; 53 | 54 | // The role of the current running sketch 55 | role_e role; 56 | 57 | // 58 | // Payload 59 | // 60 | 61 | const int min_payload_size = 1; 62 | const int max_payload_size = 32; 63 | const int payload_size_increments_by = 1; 64 | int next_payload_size = min_payload_size; 65 | 66 | char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating NULL char 67 | 68 | void setup(void) 69 | { 70 | 71 | // Simple codes for UNO nRF adapter that uses pin 10 as Vcc 72 | 73 | pinMode(10,OUTPUT); 74 | digitalWrite(10,HIGH); 75 | delay(500); 76 | 77 | // 78 | // Role 79 | // 80 | 81 | // set up the role pin 82 | pinMode(role_pin, INPUT); 83 | digitalWrite(role_pin,HIGH); 84 | delay(20); // Just to get a solid reading on the role pin 85 | 86 | // read the address pin, establish our role 87 | if ( digitalRead(role_pin) ) 88 | role = role_ping_out; 89 | else 90 | role = role_pong_back; 91 | 92 | // 93 | // Print preamble 94 | // 95 | 96 | Serial.begin(57600); 97 | printf_begin(); 98 | printf("\n\rRF24/examples/pingpair_dyn/\n\r"); 99 | printf("ROLE: %s\n\r",role_friendly_name[role]); 100 | 101 | // 102 | // Setup and configure rf radio 103 | // 104 | 105 | radio.begin(); 106 | 107 | // enable dynamic payloads 108 | radio.setCRCLength( RF24_CRC_16 ) ; 109 | radio.enableDynamicPayloads(); 110 | 111 | // optionally, increase the delay between retries & # of retries 112 | radio.setAutoAck( true ) ; 113 | radio.setPALevel( RF24_PA_HIGH ) ; 114 | 115 | radio.setRetries(5,15); 116 | 117 | // 118 | // Open pipes to other nodes for communication 119 | // 120 | 121 | // This simple sketch opens two pipes for these two nodes to communicate 122 | // back and forth. 123 | // Open 'our' pipe for writing 124 | // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) 125 | 126 | if ( role == role_ping_out ) 127 | { 128 | radio.openWritingPipe(pipes[0]); 129 | radio.openReadingPipe(1,pipes[1]); 130 | } 131 | else 132 | { 133 | radio.openWritingPipe(pipes[1]); 134 | radio.openReadingPipe(1,pipes[0]); 135 | } 136 | 137 | // 138 | // Start listening 139 | // 140 | 141 | radio.startListening(); 142 | 143 | // 144 | // Dump the configuration of the rf unit for debugging 145 | // 146 | 147 | radio.printDetails(); 148 | } 149 | 150 | void loop(void) 151 | { 152 | // 153 | // Ping out role. Repeatedly send the current time 154 | // 155 | 156 | if (role == role_ping_out) 157 | { 158 | // The payload will always be the same, what will change is how much of it we send. 159 | static char send_payload[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ789012"; 160 | 161 | // First, stop listening so we can talk. 162 | radio.stopListening(); 163 | 164 | // Take the time, and send it. This will block until complete 165 | printf("Now sending length %i...",next_payload_size); 166 | radio.write( send_payload, next_payload_size, false ); 167 | 168 | // Now, continue listening 169 | radio.startListening(); 170 | 171 | // Wait here until we get a response, or timeout 172 | unsigned long started_waiting_at = millis(); 173 | bool timeout = false; 174 | while ( ! radio.available() && ! timeout ) 175 | if (millis() - started_waiting_at > 1 + 5000/1000 ) 176 | timeout = true; 177 | 178 | // Describe the results 179 | if ( timeout ) 180 | { 181 | printf("Failed, response timed out.\n\r"); 182 | } 183 | else 184 | { 185 | // Grab the response, compare, and send to debugging spew 186 | uint8_t len = radio.getDynamicPayloadSize(); 187 | radio.read( receive_payload, len ); 188 | 189 | // Put a zero at the end for easy printing 190 | receive_payload[len] = 0; 191 | 192 | // Spew it 193 | printf("Got response size=%i value=%s\n\r",len,receive_payload); 194 | } 195 | 196 | // Update size for next time. 197 | next_payload_size += payload_size_increments_by; 198 | if ( next_payload_size > max_payload_size ) 199 | next_payload_size = min_payload_size; 200 | 201 | // Try again 1s later 202 | delay(100); 203 | } 204 | 205 | // 206 | // Pong back role. Receive each packet, dump it out, and send it back 207 | // 208 | 209 | if ( role == role_pong_back ) 210 | { 211 | // if there is data ready 212 | if ( radio.available() ) 213 | { 214 | // Dump the payloads until we've gotten everything 215 | uint8_t len; 216 | bool done = false; 217 | while (radio.available()) 218 | { 219 | // Fetch the payload, and see if this was the last one. 220 | len = radio.getDynamicPayloadSize(); 221 | radio.read( receive_payload, len ); 222 | 223 | // Put a zero at the end for easy printing 224 | receive_payload[len] = 0; 225 | 226 | // Spew it 227 | printf("Got payload size=%i value=%s\n\r",len,receive_payload); 228 | } 229 | 230 | // First, stop listening so we can talk 231 | radio.stopListening(); 232 | 233 | // Send the final one back. 234 | radio.write( receive_payload, len ); 235 | printf("Sent response.\n\r"); 236 | 237 | // Now, resume listening so we catch the next packets. 238 | radio.startListening(); 239 | } 240 | } 241 | } 242 | // vim:cin:ai:sts=2 sw=2 ft=cpp -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/pingpair_multi_dyn/pingpair_multi_dyn.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 James Coliz, Jr. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example using Dynamic Payloads 11 | * 12 | * This is an example of how to use payloads of a varying (dynamic) size. 13 | */ 14 | 15 | #include 16 | #include "RF24.h" 17 | #include "printf.h" 18 | 19 | // 20 | // Hardware configuration 21 | // 22 | 23 | // Set up nRF24L01 radio on SPI bus plus pins 8 & 9 24 | RF24 radio(8,9); 25 | 26 | // Use multicast? 27 | // sets the multicast behavior this unit in hardware. Connect to GND to use unicast 28 | // Leave open (default) to use multicast. 29 | const int multicast_pin = 6 ; 30 | 31 | // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver 32 | // Leave open to be the 'ping' transmitter 33 | const int role_pin = 7; 34 | bool multicast = true ; 35 | 36 | // 37 | // Topology 38 | // 39 | 40 | // Radio pipe addresses for the 2 nodes to communicate. 41 | const uint64_t pipes[2] = { 0xEEFAFDFDEELL, 0xEEFDFAF50DFLL }; 42 | 43 | // 44 | // Role management 45 | // 46 | // Set up role. This sketch uses the same software for all the nodes 47 | // in this system. Doing so greatly simplifies testing. The hardware itself specifies 48 | // which node it is. 49 | // 50 | // This is done through the role_pin 51 | // 52 | 53 | // The various roles supported by this sketch 54 | typedef enum { role_ping_out = 1, role_pong_back } role_e; 55 | 56 | // The debug-friendly names of those roles 57 | const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; 58 | 59 | // The role of the current running sketch 60 | role_e role; 61 | 62 | // 63 | // Payload 64 | // 65 | 66 | const int min_payload_size = 1; 67 | const int max_payload_size = 32; 68 | const int payload_size_increments_by = 1; 69 | int next_payload_size = min_payload_size; 70 | 71 | char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating NULL char 72 | 73 | void setup(void) 74 | { 75 | // 76 | // Multicast 77 | // 78 | pinMode(multicast_pin, INPUT); 79 | digitalWrite(multicast_pin,HIGH); 80 | delay( 20 ) ; 81 | 82 | // read multicast role, LOW for unicast 83 | if( digitalRead( multicast_pin ) ) 84 | multicast = true ; 85 | else 86 | multicast = false ; 87 | 88 | 89 | // 90 | // Role 91 | // 92 | 93 | // set up the role pin 94 | pinMode(role_pin, INPUT); 95 | digitalWrite(role_pin,HIGH); 96 | delay( 20 ); // Just to get a solid reading on the role pin 97 | 98 | // read the address pin, establish our role 99 | if ( digitalRead(role_pin) ) 100 | role = role_ping_out; 101 | else 102 | role = role_pong_back; 103 | 104 | // 105 | // Print preamble 106 | // 107 | 108 | Serial.begin(57600); 109 | printf_begin(); 110 | printf("\n\rRF24/examples/pingpair_multi_dyn/\n\r"); 111 | printf("ROLE: %s\n\r",role_friendly_name[role]); 112 | printf("MULTICAST: %s\r\n",(multicast?"true (unreliable)":"false (reliable)")); 113 | // 114 | // Setup and configure rf radio 115 | // 116 | 117 | radio.begin(); 118 | 119 | // enable dynamic payloads 120 | radio.enableDynamicPayloads(); 121 | radio.setCRCLength( RF24_CRC_16 ) ; 122 | 123 | // optionally, increase the delay between retries & # of retries 124 | radio.setRetries( 15, 5 ) ; 125 | radio.setAutoAck( true ) ; 126 | //radio.setPALevel( RF24_PA_LOW ) ; 127 | 128 | // 129 | // Open pipes to other nodes for communication 130 | // 131 | 132 | // This simple sketch opens two pipes for these two nodes to communicate 133 | // back and forth. 134 | // Open 'our' pipe for writing 135 | // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) 136 | 137 | if ( role == role_ping_out ) 138 | { 139 | radio.openWritingPipe(pipes[0]); 140 | radio.openReadingPipe(1,pipes[1]); 141 | } 142 | else 143 | { 144 | radio.openWritingPipe(pipes[1]); 145 | radio.openReadingPipe(1,pipes[0]); 146 | } 147 | 148 | // 149 | // Start listening 150 | // 151 | radio.powerUp() ; 152 | radio.startListening(); 153 | 154 | // 155 | // Dump the configuration of the rf unit for debugging 156 | // 157 | 158 | radio.printDetails(); 159 | } 160 | 161 | void loop(void) 162 | { 163 | // 164 | // Ping out role. Repeatedly send the current time 165 | // 166 | 167 | if (role == role_ping_out) 168 | { 169 | // The payload will always be the same, what will change is how much of it we send. 170 | static char send_payload[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ789012"; 171 | 172 | // First, stop listening so we can talk. 173 | radio.stopListening(); 174 | 175 | // Take the time, and send it. This will block until complete 176 | printf("Now sending length %i...",next_payload_size); 177 | radio.write( send_payload, next_payload_size, multicast ); 178 | 179 | // Now, continue listening 180 | radio.startListening(); 181 | 182 | // Wait here until we get a response, or timeout 183 | unsigned long started_waiting_at = millis(); 184 | bool timeout = false; 185 | while ( ! radio.available() && ! timeout ) 186 | if (millis() - started_waiting_at > 1 + radio.getMaxTimeout()/1000 ) 187 | timeout = true; 188 | 189 | // Describe the results 190 | if ( timeout ) 191 | { 192 | printf("Failed, response timed out.\n\r"); 193 | } 194 | else 195 | { 196 | // Grab the response, compare, and send to debugging spew 197 | uint8_t len = radio.getDynamicPayloadSize(); 198 | radio.read( receive_payload, len ); 199 | 200 | // Put a zero at the end for easy printing 201 | receive_payload[len] = 0; 202 | 203 | // Spew it 204 | printf("Got response size=%i value=%s\n\r",len,receive_payload); 205 | } 206 | 207 | // Update size for next time. 208 | next_payload_size += payload_size_increments_by; 209 | if ( next_payload_size > max_payload_size ) 210 | next_payload_size = min_payload_size; 211 | 212 | // Try again 1s later 213 | delay(250); 214 | } 215 | 216 | // 217 | // Pong back role. Receive each packet, dump it out, and send it back 218 | // 219 | 220 | if ( role == role_pong_back ) 221 | { 222 | // if there is data ready 223 | if ( radio.available() ) 224 | { 225 | // Dump the payloads until we've gotten everything 226 | uint8_t len; 227 | bool done = false; 228 | while (!done) 229 | { 230 | // Fetch the payload, and see if this was the last one. 231 | len = radio.getDynamicPayloadSize(); 232 | done = radio.read( receive_payload, len ); 233 | 234 | // Put a zero at the end for easy printing 235 | receive_payload[len] = 0; 236 | 237 | // Spew it 238 | printf("Got payload size=%i value=%s\n\r",len,receive_payload); 239 | } 240 | 241 | // First, stop listening so we can talk 242 | radio.stopListening(); 243 | 244 | // Send the final one back. 245 | radio.write( receive_payload, len, multicast ); 246 | printf("Sent response.\n\r"); 247 | 248 | // Now, resume listening so we catch the next packets. 249 | radio.startListening(); 250 | } 251 | } 252 | } 253 | // vim:cin:ai:sts=2 sw=2 ft=cpp 254 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/pingpair_sleepy/pingpair_sleepy.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example RF Radio Ping Pair which Sleeps between Sends 11 | * 12 | * This is an example of how to use the RF24 class to create a battery- 13 | * efficient system. It is just like the pingpair.pde example, but the 14 | * ping node powers down the radio and sleeps the MCU after every 15 | * ping/pong cycle. 16 | * 17 | * As with the pingpair.pde example, write this sketch to two different nodes, 18 | * connect the role_pin to ground on one. The ping node sends the current 19 | * time to the pong node, which responds by sending the value back. The ping 20 | * node can then see how long the whole cycle took. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include "RF24.h" 27 | #include "printf.h" 28 | 29 | // 30 | // Hardware configuration 31 | // 32 | 33 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 34 | 35 | RF24 radio(9,10); 36 | 37 | // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver 38 | // Leave open to be the 'ping' transmitter 39 | const int role_pin = 7; 40 | 41 | // 42 | // Topology 43 | // 44 | 45 | // Radio pipe addresses for the 2 nodes to communicate. 46 | const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; 47 | 48 | // 49 | // Role management 50 | // 51 | // Set up role. This sketch uses the same software for all the nodes 52 | // in this system. Doing so greatly simplifies testing. The hardware itself specifies 53 | // which node it is. 54 | // 55 | // This is done through the role_pin 56 | // 57 | 58 | // The various roles supported by this sketch 59 | typedef enum { role_ping_out = 1, role_pong_back } role_e; 60 | 61 | // The debug-friendly names of those roles 62 | const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; 63 | 64 | // The role of the current running sketch 65 | role_e role; 66 | 67 | // 68 | // Sleep declarations 69 | // 70 | 71 | typedef enum { wdt_16ms = 0, wdt_32ms, wdt_64ms, wdt_128ms, wdt_250ms, wdt_500ms, wdt_1s, wdt_2s, wdt_4s, wdt_8s } wdt_prescalar_e; 72 | 73 | void setup_watchdog(uint8_t prescalar); 74 | void do_sleep(void); 75 | 76 | const short sleep_cycles_per_transmission = 4; 77 | volatile short sleep_cycles_remaining = sleep_cycles_per_transmission; 78 | 79 | // 80 | // Normal operation 81 | // 82 | 83 | void setup(void) 84 | { 85 | // 86 | // Role 87 | // 88 | 89 | // set up the role pin 90 | pinMode(role_pin, INPUT); 91 | digitalWrite(role_pin,HIGH); 92 | delay(20); // Just to get a solid reading on the role pin 93 | 94 | // read the address pin, establish our role 95 | if ( digitalRead(role_pin) ) 96 | role = role_ping_out; 97 | else 98 | role = role_pong_back; 99 | 100 | // 101 | // Print preamble 102 | // 103 | 104 | Serial.begin(57600); 105 | printf_begin(); 106 | printf("\n\rRF24/examples/pingpair_sleepy/\n\r"); 107 | printf("ROLE: %s\n\r",role_friendly_name[role]); 108 | 109 | // 110 | // Prepare sleep parameters 111 | // 112 | 113 | // Only the ping out role sleeps. Wake up every 4s to send a ping 114 | if ( role == role_ping_out ) 115 | setup_watchdog(wdt_1s); 116 | 117 | // 118 | // Setup and configure rf radio 119 | // 120 | 121 | radio.begin(); 122 | 123 | // 124 | // Open pipes to other nodes for communication 125 | // 126 | 127 | // This simple sketch opens two pipes for these two nodes to communicate 128 | // back and forth. 129 | // Open 'our' pipe for writing 130 | // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) 131 | 132 | if ( role == role_ping_out ) 133 | { 134 | radio.openWritingPipe(pipes[0]); 135 | radio.openReadingPipe(1,pipes[1]); 136 | } 137 | else 138 | { 139 | radio.openWritingPipe(pipes[1]); 140 | radio.openReadingPipe(1,pipes[0]); 141 | } 142 | 143 | // 144 | // Start listening 145 | // 146 | 147 | radio.startListening(); 148 | 149 | // 150 | // Dump the configuration of the rf unit for debugging 151 | // 152 | 153 | radio.printDetails(); 154 | } 155 | 156 | void loop(void) 157 | { 158 | // 159 | // Ping out role. Repeatedly send the current time 160 | // 161 | 162 | if (role == role_ping_out) 163 | { 164 | // First, stop listening so we can talk. 165 | radio.stopListening(); 166 | 167 | // Take the time, and send it. This will block until complete 168 | unsigned long time = millis(); 169 | printf("Now sending %lu...",time); 170 | radio.write( &time, sizeof(unsigned long) ); 171 | 172 | // Now, continue listening 173 | radio.startListening(); 174 | 175 | // Wait here until we get a response, or timeout (250ms) 176 | unsigned long started_waiting_at = millis(); 177 | bool timeout = false; 178 | while ( ! radio.available() && ! timeout ) 179 | if (millis() - started_waiting_at > 250 ) 180 | timeout = true; 181 | 182 | // Describe the results 183 | if ( timeout ) 184 | { 185 | printf("Failed, response timed out.\n\r"); 186 | } 187 | else 188 | { 189 | // Grab the response, compare, and send to debugging spew 190 | unsigned long got_time; 191 | radio.read( &got_time, sizeof(unsigned long) ); 192 | 193 | // Spew it 194 | printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time); 195 | } 196 | 197 | // 198 | // Shut down the system 199 | // 200 | 201 | // Experiment with some delay here to see if it has an effect 202 | delay(500); 203 | 204 | // Power down the radio. Note that the radio will get powered back up 205 | // on the next write() call. 206 | radio.powerDown(); 207 | 208 | // Sleep the MCU. The watchdog timer will awaken in a short while, and 209 | // continue execution here. 210 | while( sleep_cycles_remaining ) 211 | do_sleep(); 212 | 213 | sleep_cycles_remaining = sleep_cycles_per_transmission; 214 | } 215 | 216 | // 217 | // Pong back role. Receive each packet, dump it out, and send it back 218 | // 219 | // This is untouched from the pingpair example. 220 | // 221 | 222 | if ( role == role_pong_back ) 223 | { 224 | // if there is data ready 225 | if ( radio.available() ) 226 | { 227 | // Dump the payloads until we've gotten everything 228 | unsigned long got_time; 229 | bool done = false; 230 | while (!done) 231 | { 232 | // Fetch the payload, and see if this was the last one. 233 | done = radio.read( &got_time, sizeof(unsigned long) ); 234 | 235 | // Spew it. Include our time, because the ping_out millis counter is unreliable 236 | // due to it sleeping 237 | printf("Got payload %lu @ %lu...",got_time,millis()); 238 | } 239 | 240 | // First, stop listening so we can talk 241 | radio.stopListening(); 242 | 243 | // Send the final one back. 244 | radio.write( &got_time, sizeof(unsigned long) ); 245 | printf("Sent response.\n\r"); 246 | 247 | // Now, resume listening so we catch the next packets. 248 | radio.startListening(); 249 | } 250 | } 251 | } 252 | 253 | // 254 | // Sleep helpers 255 | // 256 | 257 | // 0=16ms, 1=32ms,2=64ms,3=125ms,4=250ms,5=500ms 258 | // 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec 259 | 260 | void setup_watchdog(uint8_t prescalar) 261 | { 262 | prescalar = min(9,prescalar); 263 | uint8_t wdtcsr = prescalar & 7; 264 | if ( prescalar & 8 ) 265 | wdtcsr |= _BV(WDP3); 266 | 267 | MCUSR &= ~_BV(WDRF); 268 | WDTCSR = _BV(WDCE) | _BV(WDE); 269 | WDTCSR = _BV(WDCE) | wdtcsr | _BV(WDIE); 270 | } 271 | 272 | ISR(WDT_vect) 273 | { 274 | --sleep_cycles_remaining; 275 | } 276 | 277 | void do_sleep(void) 278 | { 279 | set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here 280 | sleep_enable(); 281 | 282 | sleep_mode(); // System sleeps here 283 | 284 | sleep_disable(); // System continues execution here when watchdog timed out 285 | radio.powerUp() ; 286 | } 287 | 288 | // vim:ai:cin:sts=2 sw=2 ft=cpp 289 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/pingpair_sleepy/pingpair_sleepy.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | 8 | TMRh20 2014 - Updates to the library allow sleeping both in TX and RX modes: 9 | TX Mode: The radio can be powered down (.9uA current) and the Arduino slept using the watchdog timer 10 | RX Mode: The radio can be left in standby mode (22uA current) and the Arduino slept using an interrupt pin 11 | */ 12 | 13 | /** 14 | * Example RF Radio Ping Pair which Sleeps between Sends 15 | * 16 | * This is an example of how to use the RF24 class to create a battery- 17 | * efficient system. It is just like the GettingStarted_CallResponse example, but the 18 | * ping node powers down the radio and sleeps the MCU after every 19 | * ping/pong cycle, and the receiver sleeps between payloads. 20 | * 21 | * Write this sketch to two different nodes, 22 | * connect the role_pin to ground on one. The ping node sends the current 23 | * time to the pong node, which responds by sending the value back. The ping 24 | * node can then see how long the whole cycle took. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include "nRF24L01.h" 31 | #include "RF24.h" 32 | #include "printf.h" 33 | 34 | 35 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 36 | RF24 radio(7,8); 37 | 38 | // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver 39 | // Leave open to be the 'ping' transmitter 40 | const int role_pin = 5; 41 | 42 | const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; // Radio pipe addresses for the 2 nodes to communicate. 43 | 44 | // Role management 45 | // Set up role. This sketch uses the same software for all the nodes 46 | // in this system. Doing so greatly simplifies testing. The hardware itself specifies 47 | // which node it is. 48 | 49 | // The various roles supported by this sketch 50 | typedef enum { role_ping_out = 1, role_pong_back } role_e; 51 | 52 | // The debug-friendly names of those roles 53 | const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; 54 | 55 | // The role of the current running sketch 56 | role_e role; 57 | 58 | 59 | // Sleep declarations 60 | typedef enum { wdt_16ms = 0, wdt_32ms, wdt_64ms, wdt_128ms, wdt_250ms, wdt_500ms, wdt_1s, wdt_2s, wdt_4s, wdt_8s } wdt_prescalar_e; 61 | 62 | void setup_watchdog(uint8_t prescalar); 63 | void do_sleep(void); 64 | 65 | const short sleep_cycles_per_transmission = 4; 66 | volatile short sleep_cycles_remaining = sleep_cycles_per_transmission; 67 | 68 | 69 | 70 | void setup(){ 71 | 72 | // set up the role pin 73 | pinMode(role_pin, INPUT); 74 | digitalWrite(role_pin,HIGH); 75 | delay(20); // Just to get a solid reading on the role pin 76 | 77 | // read the address pin, establish our role 78 | if ( digitalRead(role_pin) ) 79 | role = role_ping_out; 80 | else 81 | role = role_pong_back; 82 | 83 | Serial.begin(57600); 84 | printf_begin(); 85 | printf("\n\rRF24/examples/pingpair_sleepy/\n\r"); 86 | printf("ROLE: %s\n\r",role_friendly_name[role]); 87 | 88 | // Prepare sleep parameters 89 | // Only the ping out role uses WDT. Wake up every 4s to send a ping 90 | //if ( role == role_ping_out ) 91 | setup_watchdog(wdt_4s); 92 | 93 | // Setup and configure rf radio 94 | 95 | radio.begin(); 96 | 97 | // Open pipes to other nodes for communication 98 | 99 | // This simple sketch opens two pipes for these two nodes to communicate 100 | // back and forth. 101 | // Open 'our' pipe for writing 102 | // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) 103 | 104 | if ( role == role_ping_out ) { 105 | radio.openWritingPipe(pipes[0]); 106 | radio.openReadingPipe(1,pipes[1]); 107 | } else { 108 | radio.openWritingPipe(pipes[1]); 109 | radio.openReadingPipe(1,pipes[0]); 110 | } 111 | 112 | // Start listening 113 | radio.startListening(); 114 | 115 | // Dump the configuration of the rf unit for debugging 116 | //radio.printDetails(); 117 | } 118 | 119 | void loop(){ 120 | 121 | 122 | if (role == role_ping_out) { // Ping out role. Repeatedly send the current time 123 | radio.powerUp(); // Power up the radio after sleeping 124 | radio.stopListening(); // First, stop listening so we can talk. 125 | 126 | unsigned long time = millis(); // Take the time, and send it. 127 | printf("Now sending... %lu \n\r",time); 128 | 129 | radio.write( &time, sizeof(unsigned long) ); 130 | 131 | radio.startListening(); // Now, continue listening 132 | 133 | unsigned long started_waiting_at = millis(); // Wait here until we get a response, or timeout (250ms) 134 | bool timeout = false; 135 | while ( ! radio.available() ){ 136 | if (millis() - started_waiting_at > 250 ){ // Break out of the while loop if nothing available 137 | timeout = true; 138 | break; 139 | } 140 | } 141 | 142 | if ( timeout ) { // Describe the results 143 | printf("Failed, response timed out.\n\r"); 144 | }else{ 145 | unsigned long got_time; // Grab the response, compare, and send to debugging spew 146 | radio.read( &got_time, sizeof(unsigned long) ); 147 | 148 | printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time); 149 | } 150 | 151 | // Shut down the system 152 | delay(500); // Experiment with some delay here to see if it has an effect 153 | // Power down the radio. 154 | radio.powerDown(); // NOTE: The radio MUST be powered back up again manually 155 | 156 | // Sleep the MCU. 157 | do_sleep(); 158 | 159 | 160 | } 161 | 162 | 163 | // Pong back role. Receive each packet, dump it out, and send it back 164 | if ( role == role_pong_back ) { 165 | 166 | if ( radio.available() ) { // if there is data ready 167 | 168 | unsigned long got_time; 169 | while (radio.available()) { // Dump the payloads until we've gotten everything 170 | radio.read( &got_time, sizeof(unsigned long) ); // Get the payload, and see if this was the last one. 171 | // Spew it. Include our time, because the ping_out millis counter is unreliable 172 | printf("Got payload %lu @ %lu...",got_time,millis()); // due to it sleeping 173 | } 174 | 175 | radio.stopListening(); // First, stop listening so we can talk 176 | radio.write( &got_time, sizeof(unsigned long) ); // Send the final one back. 177 | printf("Sent response.\n\r"); 178 | radio.startListening(); // Now, resume listening so we catch the next packets. 179 | }else{ 180 | Serial.println("Sleeping"); 181 | delay(50); // Delay so the serial data can print out 182 | do_sleep(); 183 | 184 | } 185 | } 186 | } 187 | 188 | void wakeUp(){ 189 | sleep_disable(); 190 | } 191 | 192 | // Sleep helpers 193 | 194 | //Prescaler values 195 | // 0=16ms, 1=32ms,2=64ms,3=125ms,4=250ms,5=500ms 196 | // 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec 197 | 198 | void setup_watchdog(uint8_t prescalar){ 199 | 200 | uint8_t wdtcsr = prescalar & 7; 201 | if ( prescalar & 8 ) 202 | wdtcsr |= _BV(WDP3); 203 | MCUSR &= ~_BV(WDRF); // Clear the WD System Reset Flag 204 | WDTCSR = _BV(WDCE) | _BV(WDE); // Write the WD Change enable bit to enable changing the prescaler and enable system reset 205 | WDTCSR = _BV(WDCE) | wdtcsr | _BV(WDIE); // Write the prescalar bits (how long to sleep, enable the interrupt to wake the MCU 206 | } 207 | 208 | ISR(WDT_vect) 209 | { 210 | //--sleep_cycles_remaining; 211 | Serial.println("WDT"); 212 | } 213 | 214 | void do_sleep(void) 215 | { 216 | set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here 217 | sleep_enable(); 218 | attachInterrupt(0,wakeUp,LOW); 219 | WDTCSR |= _BV(WDIE); 220 | sleep_mode(); // System sleeps here 221 | // The WDT_vect interrupt wakes the MCU from here 222 | sleep_disable(); // System continues execution here when watchdog timed out 223 | detachInterrupt(0); 224 | WDTCSR &= ~_BV(WDIE); 225 | } 226 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/starping/starping.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example RF Radio Ping Star Group 11 | * 12 | * This sketch is a more complex example of using the RF24 library for Arduino. 13 | * Deploy this on up to six nodes. Set one as the 'pong receiver' by tying the 14 | * role_pin low, and the others will be 'ping transmit' units. The ping units 15 | * unit will send out the value of millis() once a second. The pong unit will 16 | * respond back with a copy of the value. Each ping unit can get that response 17 | * back, and determine how long the whole cycle took. 18 | * 19 | * This example requires a bit more complexity to determine which unit is which. 20 | * The pong receiver is identified by having its role_pin tied to ground. 21 | * The ping senders are further differentiated by a byte in eeprom. 22 | */ 23 | 24 | #include 25 | #include 26 | #include "nRF24L01.h" 27 | #include "RF24.h" 28 | #include "printf.h" 29 | 30 | // 31 | // Hardware configuration 32 | // 33 | 34 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 35 | 36 | RF24 radio(9,10); 37 | 38 | // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver 39 | // Leave open to be the 'pong' receiver. 40 | const int role_pin = 7; 41 | 42 | // 43 | // Topology 44 | // 45 | 46 | // Radio pipe addresses for the nodes to communicate. Only ping nodes need 47 | // dedicated pipes in this topology. Each ping node has a talking pipe 48 | // that it will ping into, and a listening pipe that it will listen for 49 | // the pong. The pong node listens on all the ping node talking pipes 50 | // and sends the pong back on the sending node's specific listening pipe. 51 | 52 | const uint64_t talking_pipes[5] = { 0xF0F0F0F0D2LL, 0xF0F0F0F0C3LL, 0xF0F0F0F0B4LL, 0xF0F0F0F0A5LL, 0xF0F0F0F096LL }; 53 | const uint64_t listening_pipes[5] = { 0x3A3A3A3AD2LL, 0x3A3A3A3AC3LL, 0x3A3A3A3AB4LL, 0x3A3A3A3AA5LL, 0x3A3A3A3A96LL }; 54 | 55 | // 56 | // Role management 57 | // 58 | // Set up role. This sketch uses the same software for all the nodes 59 | // in this system. Doing so greatly simplifies testing. The hardware itself specifies 60 | // which node it is. 61 | // 62 | // This is done through the role_pin 63 | // 64 | 65 | // The various roles supported by this sketch 66 | typedef enum { role_invalid = 0, role_ping_out, role_pong_back } role_e; 67 | 68 | // The debug-friendly names of those roles 69 | const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; 70 | 71 | // The role of the current running sketch 72 | role_e role; 73 | 74 | // 75 | // Address management 76 | // 77 | 78 | // Where in EEPROM is the address stored? 79 | const uint8_t address_at_eeprom_location = 0; 80 | 81 | // What is our address (SRAM cache of the address from EEPROM) 82 | // Note that zero is an INVALID address. The pong back unit takes address 83 | // 1, and the rest are 2-6 84 | uint8_t node_address; 85 | 86 | void setup(void) 87 | { 88 | // 89 | // Role 90 | // 91 | 92 | // set up the role pin 93 | pinMode(role_pin, INPUT); 94 | digitalWrite(role_pin,HIGH); 95 | delay(20); // Just to get a solid reading on the role pin 96 | 97 | // read the address pin, establish our role 98 | if ( digitalRead(role_pin) ) 99 | role = role_ping_out; 100 | else 101 | role = role_pong_back; 102 | 103 | // 104 | // Address 105 | // 106 | 107 | if ( role == role_pong_back ) 108 | node_address = 1; 109 | else 110 | { 111 | // Read the address from EEPROM 112 | uint8_t reading = EEPROM.read(address_at_eeprom_location); 113 | 114 | // If it is in a valid range for node addresses, it is our 115 | // address. 116 | if ( reading >= 2 && reading <= 6 ) 117 | node_address = reading; 118 | 119 | // Otherwise, it is invalid, so set our address AND ROLE to 'invalid' 120 | else 121 | { 122 | node_address = 0; 123 | role = role_invalid; 124 | } 125 | } 126 | 127 | // 128 | // Print preamble 129 | // 130 | 131 | Serial.begin(57600); 132 | printf_begin(); 133 | printf("\n\rRF24/examples/starping/\n\r"); 134 | printf("ROLE: %s\n\r",role_friendly_name[role]); 135 | printf("ADDRESS: %i\n\r",node_address); 136 | 137 | // 138 | // Setup and configure rf radio 139 | // 140 | 141 | radio.begin(); 142 | 143 | // 144 | // Open pipes to other nodes for communication 145 | // 146 | 147 | // The pong node listens on all the ping node talking pipes 148 | // and sends the pong back on the sending node's specific listening pipe. 149 | if ( role == role_pong_back ) 150 | { 151 | radio.openReadingPipe(1,talking_pipes[0]); 152 | radio.openReadingPipe(2,talking_pipes[1]); 153 | radio.openReadingPipe(3,talking_pipes[2]); 154 | radio.openReadingPipe(4,talking_pipes[3]); 155 | radio.openReadingPipe(5,talking_pipes[4]); 156 | } 157 | 158 | // Each ping node has a talking pipe that it will ping into, and a listening 159 | // pipe that it will listen for the pong. 160 | if ( role == role_ping_out ) 161 | { 162 | // Write on our talking pipe 163 | radio.openWritingPipe(talking_pipes[node_address-2]); 164 | // Listen on our listening pipe 165 | radio.openReadingPipe(1,listening_pipes[node_address-2]); 166 | } 167 | 168 | // 169 | // Start listening 170 | // 171 | 172 | radio.startListening(); 173 | 174 | // 175 | // Dump the configuration of the rf unit for debugging 176 | // 177 | 178 | radio.printDetails(); 179 | 180 | // 181 | // Prompt the user to assign a node address if we don't have one 182 | // 183 | 184 | if ( role == role_invalid ) 185 | { 186 | printf("\n\r*** NO NODE ADDRESS ASSIGNED *** Send 1 through 6 to assign an address\n\r"); 187 | } 188 | } 189 | 190 | void loop(void) 191 | { 192 | // 193 | // Ping out role. Repeatedly send the current time 194 | // 195 | 196 | if (role == role_ping_out) 197 | { 198 | // First, stop listening so we can talk. 199 | radio.stopListening(); 200 | 201 | // Take the time, and send it. This will block until complete 202 | unsigned long time = millis(); 203 | printf("Now sending %lu...",time); 204 | radio.write( &time, sizeof(unsigned long) ); 205 | 206 | // Now, continue listening 207 | radio.startListening(); 208 | 209 | // Wait here until we get a response, or timeout (250ms) 210 | unsigned long started_waiting_at = millis(); 211 | bool timeout = false; 212 | while ( ! radio.available() && ! timeout ) 213 | if (millis() - started_waiting_at > 250 ) 214 | timeout = true; 215 | 216 | // Describe the results 217 | if ( timeout ) 218 | { 219 | printf("Failed, response timed out.\n\r"); 220 | } 221 | else 222 | { 223 | // Grab the response, compare, and send to debugging spew 224 | unsigned long got_time; 225 | radio.read( &got_time, sizeof(unsigned long) ); 226 | 227 | // Spew it 228 | printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time); 229 | } 230 | 231 | // Try again 1s later 232 | delay(1000); 233 | } 234 | 235 | // 236 | // Pong back role. Receive each packet, dump it out, and send it back 237 | // 238 | 239 | if ( role == role_pong_back ) 240 | { 241 | // if there is data ready 242 | uint8_t pipe_num; 243 | if ( radio.available(&pipe_num) ) 244 | { 245 | // Dump the payloads until we've gotten everything 246 | unsigned long got_time; 247 | bool done = false; 248 | while (!done) 249 | { 250 | // Fetch the payload, and see if this was the last one. 251 | done = radio.read( &got_time, sizeof(unsigned long) ); 252 | 253 | // Spew it 254 | printf("Got payload %lu from node %i...",got_time,pipe_num+1); 255 | } 256 | 257 | // First, stop listening so we can talk 258 | radio.stopListening(); 259 | 260 | // Open the correct pipe for writing 261 | radio.openWritingPipe(listening_pipes[pipe_num-1]); 262 | 263 | // Retain the low 2 bytes to identify the pipe for the spew 264 | uint16_t pipe_id = listening_pipes[pipe_num-1] & 0xffff; 265 | 266 | // Send the final one back. 267 | radio.write( &got_time, sizeof(unsigned long) ); 268 | printf("Sent response to %04x.\n\r",pipe_id); 269 | 270 | // Now, resume listening so we catch the next packets. 271 | radio.startListening(); 272 | } 273 | } 274 | 275 | // 276 | // Listen for serial input, which is how we set the address 277 | // 278 | if (Serial.available()) 279 | { 280 | // If the character on serial input is in a valid range... 281 | char c = Serial.read(); 282 | if ( c >= '1' && c <= '6' ) 283 | { 284 | // It is our address 285 | EEPROM.write(address_at_eeprom_location,c-'0'); 286 | 287 | // And we are done right now (no easy way to soft reset) 288 | printf("\n\rManually reset address to: %c\n\rPress RESET to continue!",c); 289 | while(1) ; 290 | } 291 | } 292 | } 293 | // vim:ai:ci sts=2 sw=2 ft=cpp 294 | -------------------------------------------------------------------------------- /Библиотеки/RF24-master/examples/TransferTimeouts/TransferTimeouts.ino: -------------------------------------------------------------------------------- 1 | /* 2 | TMRh20 2014 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** Reliably transmitting large volumes of data with a low signal or in noisy environments 10 | * This example demonstrates data transfer functionality with the use of auto-retry 11 | and auto-reUse functionality enabled. This sketch demonstrates how a user can extend 12 | the auto-retry functionality to any chosen time period, preventing data loss and ensuring 13 | the consistency of data. 14 | 15 | This sketh demonstrates use of the writeBlocking() functionality, and extends the standard 16 | retry functionality of the radio. Payloads will be auto-retried until successful or the 17 | extended timeout period is reached. 18 | */ 19 | 20 | 21 | 22 | #include 23 | #include "nRF24L01.h" 24 | #include "RF24.h" 25 | #include "printf.h" 26 | 27 | /************* USER Configuration *****************************/ 28 | 29 | RF24 radio(48,49); // Set up nRF24L01 radio on SPI bus plus pins 7 & 8 30 | unsigned long timeoutPeriod = 3000; // Set a user-defined timeout period. With auto-retransmit set to (15,15) retransmission will take up to 60ms and as little as 7.5ms with it set to (1,15). 31 | // With a timeout period of 1000, the radio will retry each payload for up to 1 second before giving up on the transmission and starting over 32 | 33 | /***************************************************************/ 34 | 35 | const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL }; // Radio pipe addresses for the 2 nodes to communicate. 36 | 37 | byte data[32]; //Data buffer 38 | 39 | volatile unsigned long counter; 40 | unsigned long rxTimer,startTime, stopTime, payloads = 0; 41 | bool TX=1,RX=0,role=0, transferInProgress = 0; 42 | 43 | 44 | void setup(void) { 45 | 46 | Serial.begin(57600); 47 | printf_begin(); 48 | 49 | radio.begin(); // Setup and configure rf radio 50 | radio.setChannel(1); // Set the channel 51 | radio.setPALevel(RF24_PA_LOW); // Set PA LOW for this demonstration. We want the radio to be as lossy as possible for this example. 52 | radio.setDataRate(RF24_1MBPS); // Raise the data rate to reduce transmission distance and increase lossiness 53 | radio.setAutoAck(1); // Ensure autoACK is enabled 54 | radio.setRetries(2,15); // Optionally, increase the delay between retries. Want the number of auto-retries as high as possible (15) 55 | radio.setCRCLength(RF24_CRC_16); // Set CRC length to 16-bit to ensure quality of data 56 | radio.openWritingPipe(pipes[0]); // Open the default reading and writing pipe 57 | radio.openReadingPipe(1,pipes[1]); 58 | 59 | radio.startListening(); // Start listening 60 | radio.printDetails(); // Dump the configuration of the rf unit for debugging 61 | 62 | printf("\n\rRF24/examples/Transfer Rates/\n\r"); 63 | printf("*** PRESS 'T' to begin transmitting to the other node\n\r"); 64 | 65 | randomSeed(analogRead(0)); //Seed for random number generation 66 | for(int i=0; i<32; i++){ 67 | data[i] = random(255); //Load the buffer with random data 68 | } 69 | radio.powerUp(); //Power up the radio 70 | 71 | 72 | } 73 | 74 | 75 | 76 | void loop(void){ 77 | 78 | 79 | if(role == TX){ 80 | delay(2000); // Pause for a couple seconds between transfers 81 | printf("Initiating Extended Timeout Data Transfer\n\r"); 82 | 83 | unsigned long cycles = 1000; // Change this to a higher or lower number. This is the number of payloads that will be sent. 84 | 85 | unsigned long transferCMD[] = {'H','S',cycles }; // Indicate to the other radio that we are starting, and provide the number of payloads that will be sent 86 | radio.writeFast(&transferCMD,12); // Send the transfer command 87 | if(radio.txStandBy(timeoutPeriod)){ // If transfer initiation was successful, do the following 88 | 89 | startTime = millis(); // For calculating transfer rate 90 | boolean timedOut = 0; // Boolean for keeping track of failures 91 | 92 | for(int i=0; i timeoutPeriod){ // If no data available, check the timeout period 146 | Serial.println("Transfer Failed"); // If per-payload timeout exceeeded, end the transfer 147 | transferInProgress = 0; 148 | }else 149 | if(counter >= payloads){ // If the specified number of payloads is reached, transfer is completed 150 | startTime = millis() - startTime; // Calculate the total time spent during transfer 151 | float numBytes = counter*32; // Calculate the number of bytes transferred 152 | Serial.print("Rate: "); // Print the transfer rate and number of payloads 153 | Serial.print(numBytes/startTime); 154 | Serial.println(" KB/s"); 155 | printf("Payload Count: %d \n\r", counter); 156 | transferInProgress = 0; // End the transfer as complete 157 | } 158 | } 159 | 160 | 161 | } 162 | 163 | // 164 | // Change roles 165 | // 166 | 167 | if ( Serial.available() ) 168 | { 169 | char c = toupper(Serial.read()); 170 | if ( c == 'T' && role == RX ) 171 | { 172 | printf("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK\n\r"); 173 | radio.openWritingPipe(pipes[1]); 174 | radio.openReadingPipe(1,pipes[0]); 175 | radio.stopListening(); 176 | role = TX; // Become the primary transmitter (ping out) 177 | } 178 | else if ( c == 'R' && role == TX ) 179 | { 180 | radio.openWritingPipe(pipes[0]); 181 | radio.openReadingPipe(1,pipes[1]); 182 | radio.startListening(); 183 | printf("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK\n\r"); 184 | role = RX; // Become the primary receiver (pong back) 185 | } 186 | } 187 | } 188 | 189 | 190 | -------------------------------------------------------------------------------- /Библиотеки/Keypad-master/examples/DynamicKeypad/DynamicKeypad.ino: -------------------------------------------------------------------------------- 1 | /* @file DynamicKeypad.pde 2 | || @version 1.2 3 | || @author Mark Stanley 4 | || @contact mstanley@technologist.com 5 | || 6 | || 07/11/12 - Re-modified (from DynamicKeypadJoe2) to use direct-connect kpds 7 | || 02/28/12 - Modified to use I2C i/o G. D. (Joe) Young 8 | || 9 | || 10 | || @dificulty: Intermediate 11 | || 12 | || @description 13 | || | This is a demonstration of keypadEvents. It's used to switch between keymaps 14 | || | while using only one keypad. The main concepts being demonstrated are: 15 | || | 16 | || | Using the keypad events, PRESSED, HOLD and RELEASED to simplify coding. 17 | || | How to use setHoldTime() and why. 18 | || | Making more than one thing happen with the same key. 19 | || | Assigning and changing keymaps on the fly. 20 | || | 21 | || | Another useful feature is also included with this demonstration although 22 | || | it's not really one of the concepts that I wanted to show you. If you look 23 | || | at the code in the PRESSED event you will see that the first section of that 24 | || | code is used to scroll through three different letters on each key. For 25 | || | example, pressing the '2' key will step through the letters 'd', 'e' and 'f'. 26 | || | 27 | || | 28 | || | Using the keypad events, PRESSED, HOLD and RELEASED to simplify coding 29 | || | Very simply, the PRESSED event occurs imediately upon detecting a pressed 30 | || | key and will not happen again until after a RELEASED event. When the HOLD 31 | || | event fires it always falls between PRESSED and RELEASED. However, it will 32 | || | only occur if a key has been pressed for longer than the setHoldTime() interval. 33 | || | 34 | || | How to use setHoldTime() and why 35 | || | Take a look at keypad.setHoldTime(500) in the code. It is used to set the 36 | || | time delay between a PRESSED event and the start of a HOLD event. The value 37 | || | 500 is in milliseconds (mS) and is equivalent to half a second. After pressing 38 | || | a key for 500mS the HOLD event will fire and any code contained therein will be 39 | || | executed. This event will stay active for as long as you hold the key except 40 | || | in the case of bug #1 listed above. 41 | || | 42 | || | Making more than one thing happen with the same key. 43 | || | If you look under the PRESSED event (case PRESSED:) you will see that the '#' 44 | || | is used to print a new line, Serial.println(). But take a look at the first 45 | || | half of the HOLD event and you will see the same key being used to switch back 46 | || | and forth between the letter and number keymaps that were created with alphaKeys[4][5] 47 | || | and numberKeys[4][5] respectively. 48 | || | 49 | || | Assigning and changing keymaps on the fly 50 | || | You will see that the '#' key has been designated to perform two different functions 51 | || | depending on how long you hold it down. If you press the '#' key for less than the 52 | || | setHoldTime() then it will print a new line. However, if you hold if for longer 53 | || | than that it will switch back and forth between numbers and letters. You can see the 54 | || | keymap changes in the HOLD event. 55 | || | 56 | || | 57 | || | In addition... 58 | || | You might notice a couple of things that you won't find in the Arduino language 59 | || | reference. The first would be #include . This is a standard library from 60 | || | the C programming language and though I don't normally demonstrate these types of 61 | || | things from outside the Arduino language reference I felt that its use here was 62 | || | justified by the simplicity that it brings to this sketch. 63 | || | That simplicity is provided by the two calls to isalpha(key) and isdigit(key). 64 | || | The first one is used to decide if the key that was pressed is any letter from a-z 65 | || | or A-Z and the second one decides if the key is any number from 0-9. The return 66 | || | value from these two functions is either a zero or some positive number greater 67 | || | than zero. This makes it very simple to test a key and see if it is a number or 68 | || | a letter. So when you see the following: 69 | || | 70 | || | if (isalpha(key)) // this tests to see if your key was a letter 71 | || | 72 | || | And the following may be more familiar to some but it is equivalent: 73 | || | 74 | || | if (isalpha(key) != 0) // this tests to see if your key was a letter 75 | || | 76 | || | And Finally... 77 | || | To better understand how the event handler affects your code you will need to remember 78 | || | that it gets called only when you press, hold or release a key. However, once a key 79 | || | is pressed or held then the event handler gets called at the full speed of the loop(). 80 | || | 81 | || # 82 | */ 83 | #include 84 | #include 85 | 86 | const byte ROWS = 4; //four rows 87 | const byte COLS = 3; //three columns 88 | // Define the keymaps. The blank spot (lower left) is the space character. 89 | char alphaKeys[ROWS][COLS] = { 90 | { 'a','d','g' }, 91 | { 'j','m','p' }, 92 | { 's','v','y' }, 93 | { ' ','.','#' } 94 | }; 95 | 96 | char numberKeys[ROWS][COLS] = { 97 | { '1','2','3' }, 98 | { '4','5','6' }, 99 | { '7','8','9' }, 100 | { ' ','0','#' } 101 | }; 102 | 103 | boolean alpha = false; // Start with the numeric keypad. 104 | 105 | byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad 106 | byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad 107 | 108 | // Create two new keypads, one is a number pad and the other is a letter pad. 109 | Keypad numpad( makeKeymap(numberKeys), rowPins, colPins, sizeof(rowPins), sizeof(colPins) ); 110 | Keypad ltrpad( makeKeymap(alphaKeys), rowPins, colPins, sizeof(rowPins), sizeof(colPins) ); 111 | 112 | 113 | unsigned long startTime; 114 | const byte ledPin = 13; // Use the LED on pin 13. 115 | 116 | void setup() { 117 | Serial.begin(9600); 118 | pinMode(ledPin, OUTPUT); 119 | digitalWrite(ledPin, LOW); // Turns the LED on. 120 | ltrpad.begin( makeKeymap(alphaKeys) ); 121 | numpad.begin( makeKeymap(numberKeys) ); 122 | ltrpad.addEventListener(keypadEvent_ltr); // Add an event listener. 123 | ltrpad.setHoldTime(500); // Default is 1000mS 124 | numpad.addEventListener(keypadEvent_num); // Add an event listener. 125 | numpad.setHoldTime(500); // Default is 1000mS 126 | } 127 | 128 | char key; 129 | 130 | void loop() { 131 | 132 | if( alpha ) 133 | key = ltrpad.getKey( ); 134 | else 135 | key = numpad.getKey( ); 136 | 137 | if (alpha && millis()-startTime>100) { // Flash the LED if we are using the letter keymap. 138 | digitalWrite(ledPin,!digitalRead(ledPin)); 139 | startTime = millis(); 140 | } 141 | } 142 | 143 | static char virtKey = NO_KEY; // Stores the last virtual key press. (Alpha keys only) 144 | static char physKey = NO_KEY; // Stores the last physical key press. (Alpha keys only) 145 | static char buildStr[12]; 146 | static byte buildCount; 147 | static byte pressCount; 148 | 149 | static byte kpadState; 150 | 151 | // Take care of some special events. 152 | 153 | void keypadEvent_ltr(KeypadEvent key) { 154 | // in here when in alpha mode. 155 | kpadState = ltrpad.getState( ); 156 | swOnState( key ); 157 | } // end ltrs keypad events 158 | 159 | void keypadEvent_num( KeypadEvent key ) { 160 | // in here when using number keypad 161 | kpadState = numpad.getState( ); 162 | swOnState( key ); 163 | } // end numbers keypad events 164 | 165 | void swOnState( char key ) { 166 | switch( kpadState ) { 167 | case PRESSED: 168 | if (isalpha(key)) { // This is a letter key so we're using the letter keymap. 169 | if (physKey != key) { // New key so start with the first of 3 characters. 170 | pressCount = 0; 171 | virtKey = key; 172 | physKey = key; 173 | } 174 | else { // Pressed the same key again... 175 | virtKey++; // so select the next character on that key. 176 | pressCount++; // Tracks how many times we press the same key. 177 | } 178 | if (pressCount > 2) { // Last character reached so cycle back to start. 179 | pressCount = 0; 180 | virtKey = key; 181 | } 182 | Serial.print(virtKey); // Used for testing. 183 | } 184 | if (isdigit(key) || key == ' ' || key == '.') 185 | Serial.print(key); 186 | if (key == '#') 187 | Serial.println(); 188 | break; 189 | 190 | case HOLD: 191 | if (key == '#') { // Toggle between keymaps. 192 | if (alpha == true) { // We are currently using a keymap with letters 193 | alpha = false; // Now we want a keymap with numbers. 194 | digitalWrite(ledPin, LOW); 195 | } 196 | else { // We are currently using a keymap with numbers 197 | alpha = true; // Now we want a keymap with letters. 198 | } 199 | } 200 | else { // Some key other than '#' was pressed. 201 | buildStr[buildCount++] = (isalpha(key)) ? virtKey : key; 202 | buildStr[buildCount] = '\0'; 203 | Serial.println(); 204 | Serial.println(buildStr); 205 | } 206 | break; 207 | 208 | case RELEASED: 209 | if (buildCount >= sizeof(buildStr)) buildCount = 0; // Our string is full. Start fresh. 210 | break; 211 | } // end switch-case 212 | }// end switch on state function 213 | 214 | --------------------------------------------------------------------------------