Advertisement
Guest User

Sender Script (by JaWs)

a guest
Dec 7th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include "RF24.h"
  2. #include "SPI.h"
  3. #include "nRF24L01.h"
  4.  
  5. RF24 radio(6, 7);
  6. const byte addresses[][6] = {"ADDR1", "ADDR2"};
  7.  
  8. void setup() {
  9.   Serial.begin(9600);
  10.   // Serial.setTimeout(1000);
  11.   radio.begin();
  12.   radio.setAutoAck(true);
  13.   radio.setPALevel(RF24_PA_LOW);
  14.   radio.openWritingPipe(addresses[0]);
  15.   radio.openReadingPipe(1, addresses[1]);
  16.   radio.stopListening();
  17. }
  18.  
  19. void sendData(String s) {
  20.   radio.stopListening();
  21.   delay(50);
  22.   Serial.print("Sending payload ("+s+")...");
  23.   if (radio.write(s.c_str(), sizeof(s))) {
  24.     Serial.println("successfull (response received).");
  25.   } else {
  26.     Serial.println("no response.");
  27.   }
  28. }
  29.  
  30. String input;
  31. void loop() {
  32.   input = Serial.readStringUntil('\n');
  33.   if (input != "") {
  34.     sendData(input);
  35.   }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement