Botón#
Introducción#
The button class is derived from the controller base class and provides access to the EXP Controller’s buttons, allowing your robot to monitor presses to the controller’s buttons.

Acceso#
The controller class provides twelve button objects. Each object is an instance of the button class and can be accessed through a controller instance.
Objeto |
Ejemplo de uso |
Descripción |
|---|---|---|
|
|
Un botón |
|
|
Botón B |
|
|
Botón hacia abajo |
|
|
Botón L1 |
|
|
Botón L2 |
|
|
Botón L3 |
|
|
Botón R1 |
|
|
Botón R2 |
|
|
Botón R3 |
|
|
Botón de arriba |
Notas#
The
buttonobject is provided by the controller. It is not constructed directly.
Funciones de los miembros#
The Button class includes the following member functions:
pressing— Returns whether or not the specified button is being pressed.pressed— Registers a function to be called when the specified button is pressed.released— Registers a function to be called when the specified button is released.
Before calling any button member functions, a controller instance must be created, as shown below:
// Create an EXP controller instance
controller Controller = controller();
prensado#
Indica si se está pulsando un botón específico del mando.
Available Functionsbool pressing() const;
Esta función no acepta ningún parámetro.
Return ValuesDevuelve un número entero que indica si se está pulsando el botón especificado:
1— The button is being pressed.0— The button is not being pressed.
Esta función se puede llamar en cualquier objeto de botón del controlador, por ejemplo:
Controller.ButtonAController.ButtonBController.ButtonDownController.ButtonL1Controller.ButtonL2Controller.ButtonL3Controller.ButtonR1Controller.ButtonR2Controller.ButtonR3Controller.ButtonUp
// Turn right while L1 is pressed
while (true) {
if (Controller.ButtonL1.pressing()) {
Drivetrain.turn(right);
} else {
Drivetrain.stop();
}
wait(5, msec);
}
apretado#
Registra una función de devolución de llamada que se ejecuta cuando se presiona un botón específico del controlador.
Available Functionsvoid pressed(
void (* callback)(void) ) const;
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
Una función que se llama cuando se presiona el botón especificado. |
Esta función no devuelve ningún valor.
ExamplesEsta función se puede llamar en cualquier objeto de botón del controlador, por ejemplo:
Controller.ButtonAController.ButtonBController.ButtonDownController.ButtonL1Controller.ButtonL2Controller.ButtonL3Controller.ButtonR1Controller.ButtonR2Controller.ButtonR3Controller.ButtonUp
Define the callback function (outside of
int main())// Drive forward when A is pressed void driveForward() { Drivetrain.driveFor(forward, 100, mm); }Register the callback inside
int main()int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Call driveForward when the A button is pressed Controller.ButtonA.pressed(driveForward); }
liberado#
Registra una función de devolución de llamada que se ejecuta cuando se suelta un botón específico del controlador.
Available Functionsvoid released(
void (* callback)(void) ) const;
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
Una función que se llama cuando se suelta el botón especificado. |
Esta función no devuelve ningún valor.
ExamplesEsta función se puede llamar en cualquier objeto de botón del controlador, por ejemplo:
Controller.ButtonAController.ButtonBController.ButtonDownController.ButtonL1Controller.ButtonL2Controller.ButtonL3Controller.ButtonR1Controller.ButtonR2Controller.ButtonR3Controller.ButtonUp
Define the callback function (outside of
int main())// Drive backward when A is released void backUp() { Drivetrain.driveFor(reverse, 100, mm); }Register the callback inside
int main()int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Call backUp when the A button is released Controller.ButtonA.released(backUp); }