Simple software timer.
Public declarations:
class TimerOwner{ public: virtual void onTimerEvent(){} }; class RunTimer{ public: RunTimer(); RunTimer(TimerOwner* owner); RunTimer(voidFunction externFunction); void startMicros(ulong microseconds); void startMillis(ulong milliseconds); void stop(); boolean run(); boolean timerIsOn(); // Override to capture virtual void onTimerEvent(){} };
Call startMillis() or startMicros() to start the timer.
Call run() once per loop and check its return to know when time is up.
Call stop() to stop the timer.
If you prefer work with events, derive RunTimer class and rewrite onTimerEvent().
Optionally you can indicate an external function to be called. In this case, use the constructor with extern function to create RunTimer instance.
TimerOwner
Is a abstract class to receive timer events. This is usefull when the class that respond the events, can not be descending of RunTimer class. To use this way, derive TimerOwner class, rewrite the event and use the constructor with owner to create RunTimer instance.