Minutero#
Introducción#
El temporizador de VEXcode VR permite controlar el tiempo transcurrido y ejecutar acciones según intervalos de tiempo. Con diversos métodos de gestión del tiempo, puede crear operaciones precisas y sincronizadas dentro de su programa.
A continuación se muestra una lista de todos los métodos:
Métodos – Controlar e interactuar con el temporizador del cerebro.
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()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
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)
Parámetros |
Descripción |
|---|---|
|
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)
Parámetros |
Descripción |
|---|---|
|
Una función a ejecutar cuando ocurre el evento del temporizador. |
|
El retraso antes de que se llame a la función, en milisegundos. |
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)