Skip to content
Alex Krieg edited this page Nov 4, 2020 · 11 revisions

Functions

  • Timer(bool Micros = TMillis);
  • ~Timer();
  • bool update();
  • bool start(unsigned long timeOfDelayIn = 0);
  • unsigned long stop();
  • void onFinished(void (*p_func)());
  • unsigned long runtime();
  • void autoRestart(bool autoRestart);
  • bool isRunning();


Timer(bool Micros = TMillis);

Description

  • Constructor of the timer
  • Parameters are TMillis or TMicros
  • TMillis Defines the timer as an millis Timer
  • TMicros Defines the timer as an micros Timer

Syntax

Timer myTimer; Timer myTimer(TMillis);
Timer myTimer(TMicros);


~Timer();

Description

  • Destructor

Syntax

delete p_myTimer;


bool update();

Description

  • checks if the time is over
  • If Yes
    • The timer resets itself
    • If there is an defined function to call when the time is over it will by executed.
    • It returns true
  • If No
    • It returns false

Syntax

myTimer.update();


bool start(unsigned long timeOfDelayIn = 0);

Description

  • Starts the timer with the time timeOfDelayIn
  • runs update() internally
  • returns the status of update()
  • The time can by changed when the timer is still running
  • If timeOfDelayIn is 0, the Timer will never end untill stop() is called

Syntax

myTimer.start();
myTimer.start(100);

if(myTimer.start(100)) 
{ 
  //timer finished 
}

unsigned long stop();

Description

  • Stops the timer
  • Returns the current runtime

Syntax

myTimer.stop();


Events

You do not know how events work?
Look over here

void onFinished(void (*p_func)());

  • Is executed when the timer is finished.
  • NO values accepted.
  • NO return values.

unsigned long runtime();

Description

  • Returns the current runtime.
  • Value in ms when constructor initiallized with TMillis
  • Value in us when constructor initiallized with TMicros

Syntax

unsigned int runtime = myTimer.runtime();


void autoRestart(bool autoRestart);

Description

  • autoRestart(true) lets the timer automaticly restart when the timer finishes.
  • autoRestart(false) lets the timer not automaticly restart when the timer finishes. This is standard.

Syntax

myTimer.autoRestart(true);


bool isRunning();

Description

  • Returns true if the timer is running.
  • Returns false if the timer is not running.

Syntax

bool state = myTimer.isRunning();

if(myTimer.isRunning()) 
{
  //Do something 
}