Menu

RunTimer

Perrotti

Class RunTimer

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(){}
};
How to use

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.


Related

Wiki: Home
Wiki: Timer2

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.