计时器#
The timer
attribute can also be called without brain
as its own Class.
时间()#
The brain.timer.time(units)
method returns the elapsed time.
参数 |
描述 |
---|---|
单位 |
Optional. A valid TimeUnits type. The default is |
**返回:**指定单位的经过时间。
清除()#
The brain.timer.clear()
method resets the timer value to 0.
**返回:**无。
重置()#
The brain.timer.reset()
method resets the timer value.
**返回:**无。
系统()#
The brain.timer.system()
method returns the system time.
返回: 以毫秒为单位的系统时间。
系统高分辨率()#
The brain.timer.system_high_res()
method returns the high-resolution system time.
**返回:**以毫秒为单位的高分辨率系统时间。
事件()#
The brain.timer.event(callback, delay, arg)
method registers a callback function for a timer event.
参数 |
描述 |
---|---|
打回来 |
事件发生时调用的回调函数。 |
延迟 |
回调函数被调用之前的延迟。 |
arg |
**可选。**传递给回调函数的参数。 |
**返回:**无。
# Define a function timer_event
def timer_event():
# The Brain will print that timer has expired on the
# Brain's 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, ('Hello',))