定时器#

介绍#

The VEX V5’s Brain has a timer that 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.

复位定时器堆栈块。#
重置计时器

参数

描述

此代码块没有参数。

例子

一系列代码块以一个“开始时”代码块开始,后面跟着一个注释代码块,内容为“在屏幕上打印时间,并在五秒后重置时间”。在一个无限循环中,一个重置计时器代码块启动循环。当计时器小于或等于三秒时,一个while循环运行,重复执行清空第一行、设置光标并在屏幕上打印计时器值的操作。#
当开始
[Display the time the robot takes to turn right.]
驱动 [向前 v] [200] [毫米 v] ▶
重置计时器
[右 v] 转 [90] 度 ▶
在屏幕上设定打印精度为 [0.1 v]
在屏幕上打印 [Turn right took]◀ 并设定光标为下一行
在屏幕上打印 (计时器秒数)▶
在屏幕上打印 [ seconds]▶

计时器(秒)#

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.

计时器(以秒为单位)报告块。#
(计时器秒数)

参数

描述

此代码块没有参数。

例子

一系列代码块以一个 when started 代码块开始,后面跟着一个注释代码块,内容为“2 秒后显示时间”。一个 wait until 代码块会暂停执行,直到计时器达到或超过 2 秒。一旦满足此条件,一个 print 代码块会在屏幕上显示计时器的值。#
当开始
[Display the time after 2 seconds have passed.]
等到 <(计时器秒数) [math_greater_than_or_equal_to v] [2]>
在屏幕上打印 (计时器秒数)▶

当定时器#

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

定时器帽块。#
当计时器> [1] 秒

参数

描述

时间

指定附加的块堆栈开始运行前的秒数。接受整数和小数。

例子

一系列代码块,以“当计时器大于 2 秒时”代码块开始,后面跟着一个注释代码块,内容为“2 秒后播放失败音效”。当计时器超过 2 秒时,播放音效代码块会播放失败音效。#
当计时器> [2] 秒
[Display a message after 2 seconds.]
在屏幕上打印 [Time's up!]▶