Using the nrf24l01 wireless module I want to control a led with the sketch below. The transmitter automatically sends data at intervals of one second continuously and when the receiver counter reaches 2, it turns on the LED at the desired time and then turns it off. but what I want is when I turn off the power of the transmitter when 2 counts are detected from the transmitter, the led does not light up.
I want to turn the led on and off when I turn off the power of the transmitter after sending 2 signals from the transmitter.
Thank you for all the information you provide.
#include "nRF24L01.h"
#include "RF24.h"
#include "SPI.h"
int ReceivedMessage[1] = {000}; // NRF24L01 tarafından alınan değeri saklamak için kullanılır
RF24 radio(3, 4); // NRF24L01 SPI pimleri. uno'daki Pin 8 ve 9
const uint64_t pipe = 0xE6E6E6E6E6E6; // 2 NRF24L01 arasındaki iletişim için aynı olması gerekir
int led = A7;
bool flag = false;
bool ledflag = false;
unsigned long previous1 = 0;
unsigned long interval1 = 5000;
unsigned long previous2 = 0;
unsigned long interval2 = 2000;
int button1PushCounter = 0;
void setup () {
radio.begin(); // NRF24L01'i başlatın
radio.openReadingPipe(1, pipe); // NRF24L01'i almaya hazır hale getirin
radio.startListening(); // Bilginin alınıp alınmadığını görmek için dinleyin
Serial.begin(9600);
pinMode(led, OUTPUT);
}
void loop () {
unsigned long currentmillis = millis();
while (radio.available())
{
radio.read(ReceivedMessage, 1); // NRF24L01'den bilgileri okuyun
if (ReceivedMessage [0] == 111) // switch'e basıldığını gösterir
{
button1PushCounter++;
Serial.println( button1PushCounter);
delay(700);
}
if ( button1PushCounter == 2) {
flag = true;
previous1 = currentmillis;
}
if ( flag ) {
if (currentmillis - previous1 >= interval1 ) {
digitalWrite(led, HIGH);
ledflag = true;
previous2 = currentmillis;
flag = false;
button1PushCounter = 0;
}
}
if ( ledflag && (currentmillis - previous2 >= interval2 )) {
digitalWrite(led, LOW);
ledflag = false;
}
}
}
how to detect when a transmitter is turned off?