I want a function that waits for a certain signal for the condition to be met and to be able to continue with the next
for example, a function that waits for three pulses 1 second apart each through the analog port. And if this condition is met, I continued with the following function
this is the type of signal you receive through the analog pin (state> 400)
This example code is one that tries to wait for the 3 delayed pulses for a set time. But the idea is that with the function it counts the 3 pulses regardless of the time it takes to arrive so that it is more exact. Because using delays what you are reading can fail because sometimes it does not send the pulses with an exact time
void n3(){
digitalWrite(llave, HIGH);
delay(1500);
if (analogRead(led2) > 400) {
delay(4500); // wait pulse
}
digitalWrite(llave, LOW);
delay(1000);
}
And this is the other one that is supposed to wait until a continuous 2 second pulse arrives in order to continue. But the question is whether it can be done without delays. The idea is, if the function can be executed and it waits for a continuous pulse of 2 seconds to continue.
void waitpulse(){
if (analogRead(led2) > 400) {
delay(500);
if (analogRead(led2) > 400) {
delay(200);
} else {
enterpro();
}
if (analogRead(led2) > 400) {
delay(800);
} else {
enterpro();
}
if (analogRead(led2) > 400) {
delay(500);
} else {
enterpro();
}
} else {
enterpro();
}
}
I would greatly appreciate the help[