Timer#
Introduction#
The Timer in VEXcode VR 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.
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.
Usage:
brain.timer_reset()
Parameters |
Description |
|---|---|
This method has no parameters. |
def main():
# Reset the timer every 3 seconds
while True:
brain.clear()
brain.print(brain.timer.time(SECONDS))
if brain.timer_time(SECONDS) > 3:
brain.timer_reset()
wait(5, MSEC)
# VR threads — Do not delete
vr_thread(main)
timer_time#
timer_time returns the current elapsed time of the timer as a float.
Usage:
brain.timer_time(units)
Parameters |
Description |
|---|---|
|
The unit that represents the time:
|
def main():
# Display the current time on the timer
while True:
brain.clear()
brain.print(brain.timer_time(SECONDS))
wait(50, MSEC)
# VR threads — Do not delete
vr_thread(main)
timer_event#
event calls a function after a specified amount of time.
Usage:
brain.timer_event(callback, delay)
Parameters |
Description |
|---|---|
|
A function to execute when the timer event occurs. |
|
The delay before the function is called, in milliseconds. |
def timer_event():
# Drive forward
drivetrain.drive_for(FORWARD, 200, MM)
def main():
# Drive forward after a 5000 millisecond delay
brain.timer_event(timer_event, 5000)
# VR threads — Do not delete
vr_thread(main)