Timer#

timer.time()#

The timer.time() command returns the elapsed time.

This is a non-waiting command and allows the next command to run without delay.

Parameters

Description

units

Optional. A valid TimeUnit. The default is MSEC.

Returns: The elapsed time in the specified unit.

timer.clear()#

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

This is a non-waiting command and allows the next command to run without delay.

Returns: None.

timer.reset()#

The timer.reset() command resets the timer value.

This is a non-waiting command and allows the next command to run without delay.

Returns: None.

timer.system()#

The timer.system() command returns the system time.

This is a non-waiting command and allows the next command to run without delay.

Returns: The system time in milliseconds.

timer.system_high_res()#

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

This is a non-waiting command and allows the next command to run without delay.

Returns: The high-resolution system time in milliseconds.

# Get the high resolution system time in microseconds
high_res_system_time = timer_1.system_high_res()

timer.event()#

The timer.event() command registers a callback function for a timer event.

This is a non-waiting command and allows the next command to run without delay.

Parameters

Description

callback

The callback function to be called when the event occurs.

delay

The delay before the callback function is called.

arg

Optional. The arguments to pass to the callback function.

Returns: None.

# Define a function timer_event
def timer_event():
    # The brain will print that timer has expired on the brain screen.
    brain.screen.print('timer has expired ')

# Initialize a Timer object.
t1 = Timer()
# Run timer_event after 1000 milliseconds of delay.
t1.event(timer_event, 1000)

timer.value()#

The timer.value() command returns the current time in seconds.

This is a non-waiting command and allows the next command to run without delay.

Returns: The current time in seconds.