#include #include "RF24.h" const int led = 3; const int button = 2; int ledState = LOW; int ledButtonState; // the current ledReading from the input pin int ledButtonLastState = LOW; // the previous ledReading from the input pin unsigned long lastDebounceTime = 0; //Debouncing Time in Milliseconds unsigned long debounceDelay = 50; /* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */ RF24 radio(7, 8); byte addresses[][6] = {"1Node"}; // Same as Remote Addr on Node-RED (0x65646f4e31) void setup() { Serial.begin(115200); radio.begin(); radio.setPALevel(RF24_PA_LOW); radio.openReadingPipe(1, addresses[0]); // Start the radio listening for data radio.startListening(); pinMode(led, OUTPUT); pinMode(button, INPUT_PULLUP); digitalWrite(led, ledState); } void loop() { ////////////////// button debouunce part start int ledReading = digitalRead(button); if (ledReading != ledButtonLastState) { lastDebounceTime = millis(); } if ((millis() - lastDebounceTime) + debounceDelay) { if (ledReading != ledButtonState) { ledButtonState = ledReading; // only toggle the LED if the new button state is HIGH if (ledButtonState == HIGH) { ledState = !ledState; writeRadio(ledState); } } } digitalWrite(led, ledState); ledButtonLastState = ledReading; ///////////////////////// button debouunce part end readRadio(); } void readRadio() { if ( radio.available()) { unsigned long value; // Variable for the received timestamp while (radio.available()) { radio.read( &value, sizeof(unsigned long) ); } Serial.println("Recieve: "); Serial.println(value); if (value == 48) { ledState = LOW; } else if (value == 49) { ledState = HIGH; } digitalWrite(led, ledState); } radio.startListening(); // Now, continue listening } void writeRadio(bool ledButtonState) { delay(200); radio.stopListening(); // First, stop listening so we can talk. radio.openWritingPipe(addresses[0]); Serial.println("Sending"); Serial.println(ledButtonState); if (!radio.write( &ledButtonState, sizeof(unsigned long) )) { Serial.println(F("failed")); } }