Timer#

The Timer attribute can also be called without Brain as its own Class.

time()#

The time(units) method returns the elapsed time.

Parameters

Description

units

A valid TimeUnits type. The default is msec.

Returns: The elapsed time in the specified units.

clear()#

The clear() method resets the timer value to 0.

Returns: None.

reset()#

The reset() method resets the timer value.

Returns: None.

system()#

The system() method returns the system time.

Returns: The system time in milliseconds.

system_high_res()#

The system_high_res() method returns the high-resolution system time.

Returns: The high-resolution system time in milliseconds.

event()#

The event(callback, delay) method registers a callback function for a timer event.

Parameters

Description

callback

The callback function to be called when the event occurs.

delay

The delay before the callback function is called.

Returns: None.

// Create a new function timer_event().
void timer_event() {
  Brain.Screen.print("timer event");
}

int main() {
  // Run timer_event() after 100 milliseconds.
  Brain.Timer.event(timer_event, 100);
}