Minutero#
Introducción#
El temporizador 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 check button is pressed
if (Brain.buttonCheck.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
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. |
// Play a sound after 2 seconds
void tadaSound() {
Brain.playSound(tada);
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
Brain.Timer.event(tadaSound, 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 a new timer after two seconds
wait(2, seconds);
timer stopwatch;
while (true) {
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
Brain.Screen.print("Timer:");
Brain.Screen.newLine();
Brain.Screen.print("%.3f", Brain.Timer.value());
Brain.Screen.setCursor(4, 1);
Brain.Screen.print("Stopwatch:");
Brain.Screen.newLine();
Brain.Screen.print("%.3f", stopwatch.value());
wait(100, msec);
}
}