Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <SPI.h>
  2. #include "nRF24L01.h"
  3. #include "RF24.h"
  4.  
  5. RF24 radio(9, 10);
  6. byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"};
  7.  
  8. int msg[8];
  9. bool PinState;
  10. byte command;
  11.  
  12. void setup() {
  13. Serial.begin(9600);
  14. radio.begin();
  15. radio.setAutoAck(1);
  16. radio.setRetries(0, 15);
  17. radio.enableAckPayload();
  18. radio.setPayloadSize(32);
  19.  
  20. radio.openWritingPipe(address[0]);
  21. radio.setChannel(0x66);
  22.  
  23. radio.setPALevel (RF24_PA_MAX);
  24. radio.setDataRate (RF24_250KBPS);
  25.  
  26. radio.powerUp();
  27. radio.stopListening();
  28. delay(100);
  29. }
  30.  
  31. void loop() {
  32. if (Serial.available()){
  33. command=Serial.read();
  34. if (command==103) {
  35. if (PinState==1) {
  36. PinState=0;
  37. } else {
  38. PinState=1;
  39. }
  40. } else if (command==104) {
  41. if (PinState==2) {
  42. PinState=0;
  43. } else {
  44. PinState=2;
  45. }
  46. }
  47. }
  48. msg[0]=random(100);
  49. msg[1]=PinState;
  50. radio.write(&msg, sizeof(msg));
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement