Timer#

Introduction#

The Timer in VEX GO 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.

Below is a list of all methods:

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

  • reset – Resets the timer to zero.

  • time – Returns the current elapsed time of the timer.

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

Constructor – Create additional timers.

  • Timer – Creates an additional timer.

reset#

reset sets the timer to zero.

Usage:
timer.reset()

Parameters

Description

This method has no parameters.

# Build Used: Super Code Base 2.0
def main():
    # Reset the timer when the bumper is pressed
    while True:
        console.clear()
        console.print(timer.time(SECONDS))
        wait(50, MSEC)
        if bumper.is_pressed():
            timer.reset()

# Start threads — Do not delete
start_thread(main)

time#

time returns the current elapsed time of the timer in the specified units.

Usage:
timer.time(units)

Parameters

Description

units

The unit that represents the time:

  • MSEC (default) – milliseconds
  • SECONDS
# Build Used: Super Code Base 2.0
def main():
    # Display the time until the bumper is pressed
    while True:
        console.clear()
        console.print(timer.time(SECONDS))
        wait(50, MSEC)
        if bumper.is_pressed():
            timer.reset()

# Start threads — Do not delete
start_thread(main)

event#

event calls a function after a specified amount of time.

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 Functions with Parameters for more information.

# Build Used: Super Code Base 2.0
def timer_event():
    drivetrain.drive_for(FORWARD, 200, MM)

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

# Start threads — Do not delete
start_thread(main)

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:
my_timer = Timer()

Parameters

Description

This constructor has no parameters.

def main():
    # Display the time of two timers
    wait(2, SECONDS)
    timer_1 = Timer()
    while True:
        console.clear()
        console.print("Timer: ", timer.time(SECONDS))
        console.new_line()
        console.print("timer_1: ", timer_1.time(SECONDS))
        wait(15, MSEC)

# Start threads — Do not delete
start_thread(main)