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 |
Optional. A valid TimeUnits type. The default is |
Returns: The elapsed time in the specified unit.
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, arg)
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. |
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 iq2ired on the
# Brain's screen.
brain.screen.print('timer has iq2ired ')
# Initialize a Timer object.
t1 = Timer()
# Run timer_event after 1000 milliseconds of delay.
t1.event(timer_event, 1000, ('Hello',))