Advertisement
talofer99

NRF_Master

Jun 4th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1.     #include <SPI.h>
  2.     #include <nRF24L01.h>
  3.     #include <RF24.h>
  4.    
  5.     RF24 radio(8, 10); // CE, CSN FOR UNO
  6. //  RF24 radio(7, 8); // CE, CSN FOR NANO
  7.    
  8.     const byte address[6] = "00001";
  9.     int ButtonState; // For Reading Button State
  10.  
  11.     void setup() {
  12.       pinMode(2, INPUT); //Momentary for Recevier Trigger
  13.       radio.begin();
  14.       radio.openWritingPipe(address);
  15.       radio.setPALevel(RF24_PA_MIN);
  16.       radio.stopListening();
  17.     }
  18.    
  19. void loop(){
  20.    ButtonState = digitalRead(2);    // READ BUTTON ON OR OFF
  21.    const char on[3];
  22.    on[0] = 1;
  23.    on[1] = 2; // this wiil be 1000*X for the delay
  24.    on[2] = 1; // this for the slanoid value
  25.  
  26.    const char off[3];
  27.    off[0] = 0;
  28.    off[1] = 0; // not really needed
  29.    off[2] = 0; // not really needed
  30.  
  31.    if(ButtonState == 1){            //
  32.    radio.write(&on, sizeof(on));    // IF BUTTON ON, WRITE ON TO RADIO
  33.    delay(1000);                     // DELAY TO PREVENT MULTIPLE ON WRITES (AVOID DOUBLE ACTIVATION)
  34.    }
  35.    else if(ButtonState == 0){       //
  36.    radio.write(&off, sizeof(off));  // IF BUTTON OFF, WRITE OFF TO RADIO
  37.    }
  38.    delay(20);                       // DELAY BETWEEN BUTTON READS
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement