Minutero#
Introducción#
El temporizador del V5 Brain 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 — Devuelve el valor actual del temporizador.
value— Returns the elapsed time since the timer 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:
Brain.Timer.reset();
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
int main() {
vexcodeInit();
// Initializing Robot Configuration. DO NOT REMOVE!
while (true) {
// Reset the timer every time the screen is pressed
if (Brain.Screen.pressing()) {
Brain.Timer.reset();
}
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
Brain.Screen.print("Time: %.2f", Brain.Timer.value());
wait(50, msec);
}
}
Adquiridor#
value#
value returns the current elapsed time of the timer in milliseconds as a double.
Usage:
Brain.Timer.value()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Display the timer as it ticks up
while (true) {
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
Brain.Screen.print("Time: %.2f", Brain.Timer.value());
wait(50, msec);
}
}
Llamar de vuelta#
event#
event registers a function to be called once after a specified delay.
Usage:
Brain.Timer.event(callback, delay)
Parámetros |
Descripción |
|---|---|
|
Una función de devolución de llamada previamente definida que se llama automáticamente al expirar el temporizador. La función debe coincidir con la firma de devolución de llamada requerida. Consulte Funciones de devolución de llamada para obtener más información. |
|
La cantidad de tiempo a esperar antes de llamar a la devolución de llamada como doble en milisegundos. |
Callback Signature:
void callback();
Argumentos |
Descripción |
|---|---|
Esta función de devolución de llamada no tiene argumentos. |
// Turn the screen orange after 2 seconds
void turnOrange() {
Brain.Screen.clearScreen(orange);
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
Brain.Timer.event(turnOrange, 2000);
}
Constructor#
Timer#
timer creates a new timer. A new timer will start measuring time immediately when it is created.
Usage:
timer();
Parámetro |
Descripción |
|---|---|
Este constructor no tiene parámetros. |
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Display both timers after two seconds
wait(2, seconds);
timer stopwatch;
while (true) {
Brain.Screen.clearScreen();
// Show built-in timer
Brain.Screen.setCursor(1, 1);
Brain.Screen.print("Timer:");
Brain.Screen.newLine();
Brain.Screen.print("%.3f", Brain.Timer.value());
// Show new timer (2 seconds delayed)
Brain.Screen.setCursor(4, 1);
Brain.Screen.print("Stopwatch:");
Brain.Screen.newLine();
Brain.Screen.print("%.3f", stopwatch.value());
wait(100, msec);
}
}