Timer#

Introduction#

The Timer in VEX CTE allows you to track elapsed time and perform actions based on time intervals. It can be used to measure how long something takes or reset for new timing operations.

Note: The Timer is only available when a Brain has been constructed with brain = Brain(), as all Timer functionality is driven through methods on the Brain instance.

This page uses brain as the example Brain name. Replace it with your own configured name as needed.

Below is a list of all methods:

  • timer_reset – Resets the timer to zero.

  • timer_time – Returns the elapsed time since the project started.

  • timer_event – Calls a function after a specified number of milliseconds, with optional arguments.

timer_reset#

timer_reset sets the timer to zero. This can be used to time additional sections of code within the same project.

Usage:
brain.timer_reset()

Parameters

Description

This method has no parameters.

# Display the time until the move is completed
arm.move_to(-100, 200, 100, False)
while True:
    print("\033[2J")
    print(brain.timer_time(SECONDS))
    wait(50, MSEC)
    if arm.is_done():
        brain.timer_reset()

timer_time#

timer_time returns the current elapsed time of the timer in the specified units — an integer for MSEC or a float for SECONDS.

Usage:
brain.timer_time(units)

Parameters

Description

units

Optional. The unit to represent the time:

  • MSEC (default) – milliseconds, returns an integer
  • SECONDS – returns a float

# Display the time until the move is completed
arm.move_to(-100, 200, 100, False)
while True:
    print("\033[2J")
    print(brain.timer_time(SECONDS))
    wait(50, MSEC)
    if arm.is_done():
        brain.timer_reset()

timer_event#

timer_event calls a function after a specified amount of time passes.

Usage:
timer_event(callback, delay, arg)

Parameters

Description

callback

A function to execute when the timer event occurs.

delay

The delay before the function is called, in milliseconds.

arg

Optional. A tuple containing arguments to pass to the callback function. See Using Functions with Parameters for more information.

def timer_event():
    arm.move_inc(0, 100, 0)

# Drive forward after a 5000 millisecond delay
timer_event(timer_event, 5000)