SafeString  4.1.42
SafeString is a safe, robust and debuggable replacement for string processing in Arduino
millisDelay.h
Go to the documentation of this file.
1 // millisDelay.h
2 // see the tutorial https://www.forward.com.au/pfod/ArduinoProgramming/TimingDelaysInArduino.html
3 // V1.1.0 fixed repeat if stopped / finished early
4 
5 #ifndef MILLIS_DELAY_H
6 #define MILLIS_DELAY_H
7 
8 /*
9  * (c)2018 Forward Computing and Control Pty. Ltd.
10  * NSW Australia, www.forward.com.au
11  * This code is not warranted to be fit for any purpose. You may only use it at your own risk.
12  * This generated code may be freely used for both private and commercial use
13  * provided this copyright is maintained.
14  */
15 
16 
36 class millisDelay {
37  public:
38 
40 
45  void start(unsigned long delay);
46 
52  void stop();
53 
60  void repeat();
61 
69  void restart();
70 
74  void finish();
75 
80  bool justFinished();
81 
85  bool isRunning();
86 
91  unsigned long getStartTime();
92 
97  unsigned long remaining();
98 
102  unsigned long delay();
103 
104  private:
105  unsigned long ms_delay;
106  unsigned long startTime;
107  bool running; // true if delay running false when ended
108  bool finishNow; // true if finish() called to finish delay early, false after justFinished() returns true
109 };
110 #endif
millisDelay** implements a non-blocking, repeatable delay, see the detailed description.
Definition: millisDelay.h:36
void repeat()
repeat() Do same delay again but allow for a possible delay in calling justFinished() Note: if you ca...
unsigned long remaining()
How many ms remaining until delay finishes Returns 0 if finished or stopped.
void finish()
Force delay to end now.
bool justFinished()
Has the delay ended/expired or has finish() been called? justFinished() returns true just once when d...
void stop()
Stop the delay justFinished() will now never return true until after start(),restart() or repeat() ca...
void restart()
restart() Start the same delay again starting from now Note: use repeat() when justFinished() returns...
unsigned long delay()
The delay set in start.
bool isRunning()
Is the delay running, i.e.
void start(unsigned long delay)
Start a delay of this many milliseconds.
unsigned long getStartTime()
Returns the last time this delay was started, in ms, by calling start(), repeat() or restart() Return...