Temporizador#
Introducción#
El temporizador en VEX GO le permite realizar un seguimiento del tiempo transcurrido y realizar acciones basadas en intervalos de tiempo. Se puede utilizar para medir cuánto tiempo tarda algo o restablecerlo para nuevas operaciones de sincronización.
A continuación se muestra una lista de todos los métodos:
Métodos: controle e interactúe con el temporizador del cerebro.
reset– Restablece el temporizador a cero.time– Devuelve cuánto tiempo ha pasado.event– Registra una función que se llamará después de un número específico de milisegundos.
Constructor: crea temporizadores adicionales.
Timer– Crea un temporizador adicional.
restablecer#
reset ajusta el temporizador a cero. Esto se puede utilizar para programar secciones adicionales de código dentro del mismo proyecto.
Uso:
timer.reset()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# 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)
tiempo#
el time devuelve el tiempo desde que el temporizador se restableció por última vez como decimal. El temporizador se reinicia automáticamente al comienzo de un proyecto.
Uso:
timer.time(units)
Parámetros |
Descripción |
|---|---|
|
La unidad que representa el tiempo: |
# 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)
evento#
event llama a una función después de que pase una cantidad de tiempo especificada.
Usage:
timer.event(callback, delay, arg)
Parámetros |
Descripción |
|---|---|
|
Una función para ejecutar cuando se produce el evento del temporizador. |
|
El retardo antes de que se llame a la función, en milisegundos. |
|
Opcional. Una tupla que contiene argumentos para pasar a la función de devolución de llamada. Consulte Funciones con parámetros para obtener más información. |
# 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)
Constructores#
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.
Uso:
my_timer = Timer()
Parámetros |
Descripción |
|---|---|
Este constructor no tiene parámetros. |
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)