Timer#
Introduction#
The Timer in VEX CTE 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.
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#
clear sets the timer to zero.
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 |
|---|---|
|
Optional. The unit to represent the time:
|
# 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.
Usage:
timer_event(callback, delay, arg)
Parameters |
Description |
|---|---|
|
A previously defined function that executes after the specified amount of time. |
|
The delay before the function is called, in milliseconds. |
|
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)