talofer99 icon

NRF_Master

talofer99 | PRO | 06/04/19 03:01:40 PM UTC | 0 ⭐ | 315 👁️ | Never ⏰ | []
C |

1.19 KB

|

None

|

0 👍

/

0 👎

    #include <SPI.h>
    #include <nRF24L01.h>
    #include <RF24.h>
    
    RF24 radio(8, 10); // CE, CSN FOR UNO
//  RF24 radio(7, 8); // CE, CSN FOR NANO
    
    const byte address[6] = "00001";
    int ButtonState; // For Reading Button State
 
    void setup() {
      pinMode(2, INPUT); //Momentary for Recevier Trigger
      radio.begin();
      radio.openWritingPipe(address);
      radio.setPALevel(RF24_PA_MIN);
      radio.stopListening();
    }
    
void loop(){
   ButtonState = digitalRead(2);    // READ BUTTON ON OR OFF
   const char on[3];
   on[0] = 1;
   on[1] = 2; // this wiil be 1000*X for the delay 
   on[2] = 1; // this for the slanoid value 
 
   const char off[3];
   off[0] = 0;
   off[1] = 0; // not really needed 
   off[2] = 0; // not really needed 
 
   if(ButtonState == 1){            //
   radio.write(&on, sizeof(on));    // IF BUTTON ON, WRITE ON TO RADIO
   delay(1000);                     // DELAY TO PREVENT MULTIPLE ON WRITES (AVOID DOUBLE ACTIVATION)
   }
   else if(ButtonState == 0){       //
   radio.write(&off, sizeof(off));  // IF BUTTON OFF, WRITE OFF TO RADIO
   }
   delay(20);                       // DELAY BETWEEN BUTTON READS
}

Comments