Help about "if"

I did a code in which when you press a button, a delay starts an then a servo moves. But what if I wanted to set another button to cancel the previous sequence (the delay one).
I used an if to programme the button in order to start the delay...

No problem.

For help, read the "How to get the best out of this forum" post, and post your code, using code tags.

We can't see your code

If you use delay() the processor is tied up during the duration of the delay(). You can't read the button until the delay is finished.

How to use millis() for timing:
Several things at a time.
Beginner's guide to millis().
Blink without delay().

1 Like

You can't do anything during a delay().

But you can use a millis() timer (like the Blink Without Delay Example) in a "do-nothing" loop (probably a while() loop) with an if-statement to break out of the loop when the button is pressed. Or, you can use set-up a condition where the loop runs until the time is up, or the button is pushed.

1 Like