计时器#
介绍#
VEX GO 中的计时器允许您跟踪已用时间并根据时间间隔执行操作。通过多种时间管理方法,您可以在程序中创建精确且定时的操作。
以下是所有方法的列表:
方法——控制并与大脑的计时器互动。
reset
– Resets the timer to zero.time
– Returns the elapsed time since the project started.event
– Calls a function after a specified number of milliseconds, with optional arguments.
构造函数——创建额外的计时器。
Timer
– Creates an additional timer.
重置#
reset
将计时器设置为零。
用法:
timer.reset()
参数 |
描述 |
---|---|
该方法没有参数。 |
# Build Used: Super Code Base 2.0
def main():
# Reset the timer when the bumper is pressed
while True:
console.clear()
console.print(timer.time(SECONDS))
wait(50, MSEC)
if bumper.is_pressed():
timer.reset()
# Start threads — Do not delete
start_thread(main)
时间#
time
以指定的单位返回计时器的当前经过时间 — — MSEC
的整数或 SECONDS
的浮点数。
用法:
timer.time(units)
参数 |
描述 |
---|---|
|
时间单位为毫秒 |
# Build Used: Super Code Base 2.0
def main():
# Display the time until the bumper is pressed
while True:
console.clear()
console.print(timer.time(SECONDS))
wait(50, MSEC)
if bumper.is_pressed():
timer.reset()
# Start threads — Do not delete
start_thread(main)
事件#
event
在指定时间后调用一个函数。
用法:
timer.event(callback, delay)
参数 |
描述 |
---|---|
|
当计时器事件发生时执行的函数。 |
|
函数调用前的延迟,以毫秒为单位。 |
# Build Used: Super Code Base 2.0
def timer_event():
drivetrain.drive_for(FORWARD, 200, MM)
def main():
# Drive forward after a 5000 millisecond delay
timer.event(timer_event, 5000)
# Start threads — Do not delete
start_thread(main)
构造函数#
Timer#
Timer
创建一个新的计时器。2 Timer
对象将在创建后立即开始计数,并可与所有 timer
方法配合使用。
用法:
my_timer = Timer()
参数 |
描述 |
---|---|
此构造函数没有参数。 |
def main():
# Display the time of two timers
wait(2, SECONDS)
timer_1 = Timer()
while True:
console.clear()
console.print("Timer: ", timer.time(SECONDS))
console.new_line()
console.print("timer_1: ", timer_1.time(SECONDS))
wait(15, MSEC)
# Start threads — Do not delete
start_thread(main)