Timer#

Introduction#

The Timer in VEX V5 allows you to track elapsed time and perform actions based on time intervals. With various methods for time management, you can create precise and timed operations within your program.

This page uses timer as the example Timer name. Replace it with your own configured name as needed.

Below is a list of all methods:

Methods – Control and interact with the Brain’s timer.

  • clear – 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.

Constructor – Create additional timers.

  • Timer – Creates an additional timer.

clear#

clear sets the timer to zero.

Usage:
timer.clear()

Parameters

Description

This method has no parameters.

# Reset the timer when the Bumper Switch is pressed
while True:
    print("\033[2J")
    print(timer.time(SECONDS))
    wait(50, MSEC)
    if bumper_switch.pressing():
        timer.clear()

time#

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

Usage:
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 Bumper Switch is pressed
while True:
    print("\033[2J")
    print(timer.time(SECONDS))
    wait(50, MSEC)
    if bumper_switch.pressing():
        timer.clear()

event#

event calls a function after a specified amount of time.

Usage:
timer.event(callback, delay, arg)

Parameters

Description

callback

A previously defined function that executes after the specified amount of time.

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():
    drivetrain.drive_for(FORWARD, 200, MM)

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

Constructors#

Timer#

Timer creates a new timer. A Timer object will immediately begin counting the moment it is created and will work with all timer methods.

Usage:
Timer

Parameters

Description

This constructor has no parameters.

# Create a Timer
timer = Timer()