Minutero#

Introducción#

El temporizador de VEXcode VR permite controlar el tiempo transcurrido y realizar acciones en función de intervalos de tiempo. Se puede usar para medir la duración de una tarea o para reiniciarla y realizar nuevas operaciones de temporización.

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 how much time has passed.

  • timer_event – Registers a function to be called after a specified number of milliseconds.

timer_reset#

timer_reset sets the timer to zero. This can be used to time additional sections of code within the same project.

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 time since the timer was last reset as a decimal. The timer is automatically reset at the start of a project.

Usage:
brain.timer_time(units)

Parámetros

Descripción

units

The unit that represents the time: SECONDS

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#

timer_event calls a function after a specified amount of time passes.

Usage:
brain.timer_event(callback, delay)

Parámetros

Descripción

callback

Una función a ejecutar cuando ocurre el evento del temporizador.

delay

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)