Created
January 6, 2020 00:31
-
-
Save futureshocked/a9d72f8dda78de3b7ea02b153d75b732 to your computer and use it in GitHub Desktop.
An updated version of bare_receiver.ino to work with newer versions of the RF24 library.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <SPI.h> | |
| #include "nRF24L01.h" | |
| #include "RF24.h" | |
| class RF24Test: public RF24 | |
| { | |
| public: RF24Test(int a, int b): RF24(a,b) {} | |
| }; | |
| RF24Test radio(9,10); | |
| // Radio pipe addresses for the 2 nodes to communicate. | |
| const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; | |
| void setup() | |
| { | |
| Serial.begin(57600); | |
| radio.begin(); | |
| radio.openWritingPipe(pipes[1]); | |
| radio.openReadingPipe(1,pipes[0]); | |
| radio.startListening(); | |
| Serial.println("Listening..."); | |
| } | |
| void loop() | |
| { | |
| // if there is data ready | |
| if ( radio.available() ) | |
| { | |
| byte transmission[7]; | |
| // bool done = false; // No longer using this bool since radio.read returns void | |
| // while (!done) | |
| // { | |
| // Fetch the payload, and see if this was the last one. | |
| // done = radio.read( &transmission, 7 ); | |
| radio.read( &transmission, sizeof(transmission) ); // radio.read returns void. | |
| // Spew it | |
| Serial.print(transmission[0]); | |
| Serial.print(" "); | |
| Serial.print(transmission[1]); | |
| Serial.print(" "); | |
| Serial.print(transmission[2]); | |
| Serial.print(" "); | |
| Serial.print(transmission[3]); | |
| Serial.print(" "); | |
| Serial.print(transmission[4]); | |
| Serial.print(" "); | |
| Serial.print(transmission[5]); | |
| Serial.print(" "); | |
| Serial.print(transmission[6]); | |
| Serial.print(" "); | |
| // Delay just a little bit to let the other unit | |
| // make the transition to receiver | |
| delay(20); | |
| // } | |
| // First, stop listening so we can talk | |
| radio.stopListening(); | |
| // Send the final one back. | |
| byte response = B0; | |
| radio.write( &response, sizeof(response) ); | |
| Serial.println("Sent response.\n\r"); | |
| // Now, resume listening so we catch the next packets. | |
| radio.startListening(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment