I am trying to program an arduino due to send a pulse when it receives a signal at the first time it sees it high, then sends a pulse approximately 1 second after the last detected high of the signal. The second part works as when I lower the amplitude to 0 volts, the due sends a pulse out for any duration and does not send anything else. However, the due continuously sends the pulse for when it sees the signal is high, but I only need to do that once. I attached the current program that I have been using.
switch (buttonState) {
case LOW:
while (buttonState == LOW && timer < 1001 && X == 0)
{
timer = timer + 1;
delay(1);
if (buttonState == LOW && timer == 1000)
{
digitalWrite(OUT, HIGH);
delay(1000);
digitalWrite(OUT, LOW);
X = 1;
}
else {
X = 0;
}
}
timer = 0;
break;
default:
if (buttonState == HIGH)
{
Since you never overwrite the value in buttonState, if it enters the case LOW: section, buttonState is CLEARLY LOW, so testing for LOW again is pointless.
If it is NOT LOW, there is not a snowball’s chance in hell of it being anything other then HIGH, so again it is pointless to check.