Minutero#
Introducción#
El temporizador del controlador de drones VEX AIR registra el tiempo transcurrido desde el inicio de un proyecto. Puede usarse para medir duraciones, activar eventos tras un tiempo determinado o reiniciarse para nuevas operaciones de cronometraje.
A continuación se muestra una lista de todos los métodos disponibles:
Acción – Controlar el temporizador.
reset
– Resets the timer to zero.
Getter – Informa el valor actual del temporizador.
time
– Returns the elapsed time since the project started.
Devolución de llamada: activa funciones después de un retraso.
event
– Calls a function after a specified number of milliseconds, with optional arguments.
Constructor: crea un temporizador para controlar el tiempo.
Timer
- Create a new timer object that can be used with these methods.
Acción#
reset#
reset
sets the timer to zero.
Usage:
timer.reset()
Parámetros |
Descripción |
---|---|
Este método no tiene parámetros. |
# Display the time the drone takes to climb upwards.
drone.take_off(500)
timer.reset()
drone.climb_for(UP, 500)
controller.screen.print("Time elapsed: ")
controller.screen.print(timer.time(SECONDS))
drone.land()
Adquiridor#
time#
time
returns the current elapsed time of the timer in the specified units — an integer for MSEC
or a float for SECONDS
.
Usage:
timer.time(units)
Parámetros |
Descripción |
---|---|
|
The units that represent the time:
|
# Display the time in two units.
while True:
controller.screen.clear_screen()
controller.screen.set_cursor(1, 1)
controller.screen.print("Time: {} ms".format(timer.time(MSEC)))
controller.screen.next_row()
controller.screen.print("Time: {:.2f} s".format(timer.time(SECONDS)))
wait(50, MSEC)
Llamar de vuelta#
event#
event
calls a function after a specified amount of time.
Uso:
timer.event(callback, delay, arg)
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. |
|
Opcional. Una tupla que contiene los argumentos que se pasarán a la función de devolución de llamada. Consulte Uso de eventos con parámetros para obtener más información. |
# Create a function to play a looping sound.
def on_timer():
controller.sound.play(LOOPING)
# Play the sound after 4 seconds (4000 mS).
timer.event(on_timer, 4000)
Constructor#
Timer#
A new timer can be created using the Timer
constructor. A new timer starts measuring time immediately when it is created.
Usage:
Timer()
Parámetro |
Descripción |
---|---|
Este constructor no tiene parámetros. |
# Display 2 timers with a 2 second difference.
wait(2, SECONDS)
stopwatch = Timer()
while True:
controller.screen.clear_screen()
controller.screen.set_cursor(1, 1)
controller.screen.print("Timer: ")
controller.screen.print(timer.time(SECONDS))
controller.screen.set_cursor(4, 1)
controller.screen.print("Stopwatch: ")
controller.screen.print(stopwatch.time(SECONDS))
wait(0.1, SECONDS)