Advertisement
zidniilma

Receiver nFR24L01

May 19th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <nRF24L01.h>
  3. #include <RF24.h>
  4. #include <Wire.h>
  5.  
  6. int distance;
  7. RF24 radio(7, 8);
  8. const uint64_t pipes[3] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0E2LL, 0xF0F0F0F0E3LL };
  9.  
  10. void setup(void) {
  11.   // put your setup code here, to run once:
  12.   Serial.begin(9600);
  13. radio.begin();
  14. radio.setDataRate(RF24_250KBPS);
  15. radio.openReadingPipe(1, pipes[1]);
  16. //radio.openReadingPipe(2, pipes[2]);
  17. radio.startListening();
  18.  
  19. }
  20.  
  21. void loop(void) {
  22.   // put your main code here, to run repeatedly:
  23.    if ( radio.available() )
  24.   {
  25.       float distance; // Fetch the data payload
  26.       //radio.read(&distance,sizeof(distance));
  27.       memset(&distance,' ',sizeof(distance));
  28.        radio.read(&distance,sizeof(distance));      
  29.       Serial.print("X = ");
  30.       Serial.println(distance);
  31.      
  32.      // Serial.println(distance);
  33.      
  34.       delay(500);
  35.        
  36.  
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement