hi everyone.
need help on how to cancel delay when the program is running.?
There is no way to cancel delay()! Please take a look at File -> Examples -> Digital -> BlinkWithoutDelay (in the IDE) for a better way of timing!
how sad..
this is my concept..
on led for 5sec..
and can off led although the time delay is not met.
It's not sad. Just have a look at the example. Best to forget delay() even exists. On a micro controller you NEVER want stuff to be delayed. You just want to schedule things in the future to be done Aka, after you turn on the LED you plan to turn it off 5 seconds in the future
The functions delay() and delayMicroseconds() block the Arduino until they complete.
Have a look at how millis() is used to manage timing without blocking in Several Things at a Time.
And see Using millis() for timing. A beginners guide if you need more explanation.
...R
There are a couple of REALLY NASTY ways to get out of a delay() if your program isn’t doing anything else...
One is to put a much shorter delay() inside a for-loop() that adds up to the required period, and test the exit conditions to exit that loop.
Don’t tell anyone you read it here...!
... or learn how to it properly with millis(), and good code structure.
Push the Reset button.
Delay cancelled.
delay() tells it to do nothing for the specified amount of time.
You don't want to it to do nothing, you want it to be checking if another button has been pressed so it can change behavior based on that.
Hence, delay() isn't what you want, and you need to move to millis() as others have said.
geofmen:
hi everyone.
need help on how to cancel delay when the program is running.?
20 posts !
Sorry but this is just nonsense.
You give us zero information on what and why.
You show us no attempts at writing a sketch.
You don’t tell us anything about your project.
We see no schematics.
If you want help, read the stickies that explain how to post on the forum.
Study how a state machine and millis() can be used to do what you want.