Advertisement
Guest User

Untitled

a guest
Jan 15th, 2024
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <nRF24L01.h>
  3. #include <RF24.h>
  4.  
  5. RF24 radio(10, 9); // CE, CSN pins
  6. const byte address[6] = "1Node"; // Unique address
  7. double errors = 0, itterations = 0;
  8.  
  9. void setup() {
  10. Serial.begin(9600);
  11. //SPI.begin();
  12. //SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE0));
  13. radio.begin();
  14. radio.openWritingPipe(address); // For transmitter
  15. radio.openReadingPipe(1, address);
  16. //radio.setChannel(10);
  17. radio.setPALevel(RF24_PA_MIN);
  18.  
  19. delay(1000);
  20. }
  21.  
  22. void loop() {
  23. //radio.stopListening(); // For receiver, uncomment this line
  24. radio.startListening();
  25. if (radio.available()) { // For receiver
  26. char text[32] = "";
  27. radio.read(&text, sizeof(text));
  28. if(text == ""){
  29. Serial.println(text);
  30. }
  31. }
  32. radio.stopListening();
  33. /*else { // For transmitter
  34. if(itterations >= 50){
  35. Serial.println((1 - (errors / itterations)));
  36. delay(5000);
  37. itterations = 0;
  38. errors = 0;
  39. }
  40. radio.stopListening();
  41. const char text[] = "Hello from UNO";
  42. bool report = radio.write(&text, sizeof(text));
  43. if (report) {
  44. Serial.println("Data sent successfully");
  45. } else {
  46. Serial.println("Sending failed");
  47. errors+=1;
  48. }
  49. //}*/
  50. delay(100);
  51. //itterations += 1;
  52. //Serial.println(itterations);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement