Advertisement
talofer99

NRF_SLAVE

Jun 4th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 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.  
  9.  
  10. const byte address[6] = "00001";
  11. int ActivationDelay = 2000; // TARGET ACTIVATION DELAY TIME
  12. int SolenoidTime = 250;     // DURATION FOR SOLENOID TO BE TRIGGERED
  13. long SerialInput;
  14.  
  15. void setup() {
  16.       pinMode(2, OUTPUT);       // LED CONTROL ON/OFF
  17.       pinMode(3, OUTPUT);       // RELAY CONTROL ON/OFF
  18.       Serial.begin(9600);
  19.       Serial.setTimeout (10);   // SET DELAY BETWEEN ENTER IN SERIAL MONITOR AND PARSING STRING
  20.       radio.begin();
  21.       radio.openReadingPipe(0, address);
  22.       radio.setPALevel(RF24_PA_MIN);
  23.       radio.startListening();  
  24.     }
  25.    
  26. void loop() {
  27. // SECTION FOR READING REMOTE BUTTON STATE AND CONTROLLING RELAY //
  28.        while (radio.available()) {
  29.         char text[3] = "";
  30.         radio.read(&text, sizeof(text));
  31.         Serial.println(text);
  32.        
  33.         if text[0] == 1  { // this is the ON
  34.              digitalWrite(2, HIGH); // TRIGGER LED ON
  35.              delay(text[1]*1000);// ACTIVATION DELAY TIMER
  36.              digitalWrite(3, HIGH); // RELAY CLOSED
  37.              delay(text[2]*250);   // SOLENOID CHARGE DURATION TIME        
  38.              digitalWrite(3, LOW);  // RELAY OPEN
  39.              digitalWrite(2, LOW);  // TRIGGER LED OFF
  40.         } else {
  41.              digitalWrite(2, LOW); // TRIGGER LED OFF
  42.              digitalWrite(3, LOW); // RELAY OPEN
  43.         }
  44.        
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement