SafeString
4.1.27
SafeString is a safe, robust and debuggable replacement for string processing in Arduino
|
millisDelay** implements a non-blocking, repeatable delay, see the detailed description. More...
#include <millisDelay.h>
Inherited by PinFlasher [protected]
.
Public Member Functions | |
millisDelay () | |
void | start (unsigned long delay) |
Start a delay of this many milliseconds. More... | |
void | stop () |
Stop the delay justFinished() will now never return true until after start(),restart() or repeat() called again. More... | |
void | repeat () |
repeat() Do same delay again but allow for a possible delay in calling justFinished() More... | |
void | restart () |
restart() Start the same delay again starting from now Note: use repeat() when justFinished() returns true, if you want a regular repeating delay More... | |
void | finish () |
Force delay to end now. More... | |
bool | justFinished () |
Has the delay ended/expired or has finish() been called? justFinished() returns true just once when delay first exceeded or the first time it is called after finish() called. More... | |
bool | isRunning () |
Is the delay running, i.e. More... | |
unsigned long | getStartTime () |
Returns the last time this delay was started, in ms, by calling start(), repeat() or restart() Returns 0 if it has never been started. More... | |
unsigned long | remaining () |
How many ms remaining until delay finishes Returns 0 if finished or stopped. More... | |
unsigned long | delay () |
The delay set in start. More... | |
millisDelay** implements a non-blocking, repeatable delay, see the detailed description.
To use millisDelay, create a global instance for each delay you need e.g.
millisDelay ledDelay;
Then start the delay running with with say a 1sec (1000ms) delay i.e.
ledDelay.start(1000);
This is often done in setup()
Then in loop() check if the delay has timed out with
if (ledDelay.justFinished()) {
. . . do stuff here when delay has timed out
}
The justFinished() method only returns true once the first time it is check after the delay has timeout.
NOTE: It is very important that if (ledDelay.justFinished()) {
is called every loop and that it is at the outer most level of the loop() method.
That is must not be inside another if() while() case() etc statement. It can be inside a method call as long as that method is called every loop.
See How to code Timers and Delays in Arduino for more examples
Definition at line 35 of file millisDelay.h.
millisDelay::millisDelay | ( | ) |
unsigned long millisDelay::delay | ( | ) |
The delay set in start.
void millisDelay::finish | ( | ) |
Force delay to end now.
unsigned long millisDelay::getStartTime | ( | ) |
bool millisDelay::isRunning | ( | ) |
Is the delay running, i.e.
justFinished() will return true at some time in the future
bool millisDelay::justFinished | ( | ) |
Has the delay ended/expired or has finish() been called? justFinished() returns true just once when delay first exceeded or the first time it is called after finish() called.
unsigned long millisDelay::remaining | ( | ) |
How many ms remaining until delay finishes Returns 0 if finished or stopped.
void millisDelay::repeat | ( | ) |
repeat() Do same delay again but allow for a possible delay in calling justFinished()
void millisDelay::restart | ( | ) |
restart() Start the same delay again starting from now Note: use repeat() when justFinished() returns true, if you want a regular repeating delay
void millisDelay::start | ( | unsigned long | delay | ) |
Start a delay of this many milliseconds.
delay | in millisconds, 0 means ifFinished() return true on first call |
void millisDelay::stop | ( | ) |
Stop the delay justFinished() will now never return true until after start(),restart() or repeat() called again.