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.

Botones del controlador VEX EXP resaltados en amarillo.

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

ButtonA

Controller.ButtonA.pressing()

Un botón

ButtonB

Controller.ButtonB.pressing()

Botón B

ButtonDown

Controller.ButtonDown.pressing()

Botón hacia abajo

ButtonL1

Controller.ButtonL1.pressing()

Botón L1

ButtonL2

Controller.ButtonL2.pressing()

Botón L2

ButtonL3

Controller.ButtonL3.pressing()

Botón L3

ButtonR1

Controller.ButtonR1.pressing()

Botón R1

ButtonR2

Controller.ButtonR2.pressing()

Botón R2

ButtonR3

Controller.ButtonR3.pressing()

Botón R3

ButtonUp

Controller.ButtonUp.pressing()

Botón de arriba

Notas#

  • The button object 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 Functions
bool pressing() const;

Parameters

Esta función no acepta ningún parámetro.

Return Values

Devuelve 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.
Examples

Esta función se puede llamar en cualquier objeto de botón del controlador, por ejemplo:

  • Controller.ButtonA
  • Controller.ButtonB
  • Controller.ButtonDown
  • Controller.ButtonL1
  • Controller.ButtonL2
  • Controller.ButtonL3
  • Controller.ButtonR1
  • Controller.ButtonR2
  • Controller.ButtonR3
  • Controller.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 Functions
void pressed( 
  void (* callback)(void) ) const;

Parameters

Parámetro

Tipo

Descripción

callback

void (*)(void)

Una función que se llama cuando se presiona el botón especificado.

Return Values

Esta función no devuelve ningún valor.

Examples

Esta función se puede llamar en cualquier objeto de botón del controlador, por ejemplo:

  • Controller.ButtonA
  • Controller.ButtonB
  • Controller.ButtonDown
  • Controller.ButtonL1
  • Controller.ButtonL2
  • Controller.ButtonL3
  • Controller.ButtonR1
  • Controller.ButtonR2
  • Controller.ButtonR3
  • Controller.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 Functions
void released( 
  void (* callback)(void) ) const;

Parameters

Parámetro

Tipo

Descripción

callback

void (*)(void)

Una función que se llama cuando se suelta el botón especificado.

Return Values

Esta función no devuelve ningún valor.

Examples

Esta función se puede llamar en cualquier objeto de botón del controlador, por ejemplo:

  • Controller.ButtonA
  • Controller.ButtonB
  • Controller.ButtonDown
  • Controller.ButtonL1
  • Controller.ButtonL2
  • Controller.ButtonL3
  • Controller.ButtonR1
  • Controller.ButtonR2
  • Controller.ButtonR3
  • Controller.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);
}