计时器#

简介#

The VEX AIM Coding Robot’s timer keeps track of elapsed time from the start of a project. It can be used to measure how long something takes, trigger events after a set time, or reset for new timing operations.

以下是所有模块的列表:

重置计时器#

The reset timer stack block resets the timer to zero. This can be used to start timing a new part of a project without restarting the whole project.

重置计时器指令块。#
reset timer

参数

描述

该指令块没有参数。

示例

一个指令段,以“当程序启动时”指令块开始,其后跟着一个注释指令块,内容为“在屏幕上打印时间并在五秒后重置时间”。该指令段内部是一个无限循环,其中包含一个“重置计时器”指令块来启动计时周期。一个“当”循环在计时器时间小于或等于3秒时持续运行,反复执行以下操作:清空屏幕第1行、设置光标位置,并在屏幕上打印计时器的值。#
when started
[Display the time the robot takes to turn right.]
move [forward v] for (20) [mm v] ▶
reset timer
turn [right v] for (90) degrees ▶
print [Turn right took] on screen ◀ and set cursor to next row
print (timer in seconds) on screen ▶
print [seconds] on screen ▶

计时器(以秒为单位)#

The timer in seconds reporter block reports the time since the timer was last reset, as a decimal in seconds. The timer is automatically reset at the start of a project. This block can be used to time how long it takes the robot to complete different actions.

计时器秒数报告指令块。#
(timer in seconds)

参数

描述

该指令块没有参数。

示例

一个指令段,以“当程序启动时”指令块开始,其后跟着一个注释指令块,内容为“在2秒后显示时间”。一个“等待直到”指令块会暂停执行,直到计时器的时间达到或超过2秒。一旦满足此条件,一个“打印”指令块就会在屏幕上显示计时器的值。#
when started
[Display the time after 2 seconds have passed.]
wait until < (timer in seconds) [math_greater_than_or_equal_to v] [2] >
print (timer in seconds) on screen ▶

当计时器#

The when timer hat block runs the attached stack of blocks after a specified amount of time.

计时器帽子指令块。#
when timer > [1] seconds

参数

描述

时间

设定其所连指令段启动前需等待的秒数。可接受整数和小数。

示例

一个指令段,以“当计时器时间超过 2 秒”指令块开始,其后跟着一个注释指令块,内容为“2秒后播放失败音效”。当计时器时间超过2秒后,一个“播放声音”指令块会播放失败音效。#
when timer > [2] seconds
[Play a fail sound after 2 seconds.]
play sound [fail v] ▶