Advertisement
Guest User

Untitled

a guest
May 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <nRF24L01.h>
  2. #include <printf.h>
  3. #include <RF24.h>
  4. #include <RF24_config.h>
  5. #include <Wire.h>
  6. #include <SPI.h>
  7.  
  8. RF24 radio(7, 6); // CE, CSN
  9. const byte SendAddress[6] = "006";
  10. const byte ReceiveAddress[6] = "005";
  11.  
  12. void setup() {
  13.     Serial.begin(9600);
  14.     radio.begin();
  15.     radio.openWritingPipe(SendAddress);
  16.     radio.openReadingPipe(1, ReceiveAddress);
  17.     radio.setPALevel(RF24_PA_MAX);
  18. }
  19.  
  20. void loop() {
  21.     radioReceive();
  22.     radioSend("test");
  23.     delay(250);
  24. }
  25.  
  26. void radioReceive() {
  27.     radio.startListening();
  28.     if (radio.available()) {
  29.       char text[32] = "";
  30.       radio.read(&text, sizeof(text));
  31.       Serial.println(text);
  32.     }
  33. }
  34.  
  35. void radioSend(String text) {
  36.     const char *cstr = text.c_str();
  37.     radio.stopListening();
  38.     radio.write(&cstr, sizeof(cstr));
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement