Timer#

Introduction#

The VEX IQ (2nd gen)’s brain has a timer that keeps track of elapsed time from the start of a project. It can be used to measure durations, trigger events after a set time, or reset for new timing operations. Below is a list of all available blocks:

  • reset timer – Resets the timer to zero.

  • timer in seconds – Returns the current elapsed time in seconds.

  • when timer – Runs a stack of blocks after the timer exceeds a specified time.

Events#

when timer#

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

The when timer hat block.#
  when timer > [1] seconds :: hat events

Parameters

Description

time

Specifies the number of seconds before the attached stack of blocks starts. Accepts both whole and decimal numbers.

Example

A stack of blocks that begins with a when timer > 2 seconds block, followed by a comment block reading Play a fail after 2 seconds. Once the timer exceeds two seconds, a play sound block plays the fail sound.#
  when timer > [2] seconds :: hat events
  [Play a sound after 2 seconds.]
  play sound [alarm v]

Sensing#

reset timer#

The reset timer block resets the timer to zero.

The reset timer stack block.#
  reset timer :: custom-orientation

Parameters

Description

This block has no parameters.

Example

A stack of blocks that begins with a when started block, followed by a comment block reading Print the time on the screen and reset the time after five seconds. Inside a forever loop, a reset timer block starts the cycle. A while loop runs while the timer is less than or equal to three seconds, repeatedly clearing row 1, setting the cursor, and printing the timer value on the screen.#
  when started :: hat events
  [Display the time the robot takes to turn right.]
  drive [forward v] for (200) [mm v] ▶
  reset timer :: custom-orientation
  turn [right v] for (90) degrees ▶
  set print precision to [0.1 v] on [Brain v]
  print [Turn right took] on [Brain v] ◀ and set cursor to next row
  print (timer in seconds) on [Brain v] ▶
  print [ seconds] on [Brain v] ▶
  

timer in seconds#

The timer in seconds block returns the elapsed time since the timer was last reset, as a float in seconds.

The timer in seconds reporter block.#
  (timer in seconds)

Parameters

Description

This block has no parameters.

Example

A stack of blocks that begins with a when started block, followed by a comment block reading Display the time after 2 seconds have passed. A wait until block pauses execution until the timer reaches or exceeds two seconds. Once this condition is met, a print block displays the timer value on the screen.#
  when started :: hat events
  [Display the time it takes to move in a square.]
  repeat (4)
  drive [forward v] for (100) [mm v] ▶
  turn [right v] for (90) degrees ▶
  end
  set print precision to [0.01 v] on [Brain v]
  print (timer in seconds) on [Brain v] ▶