Botón#

Introducción#

The button class is a derived class of the controller class. It provides access to Controller button states and button event callbacks.

A button object is accessed through a controller object. It is not constructed directly.

Parte frontal y posterior del controlador V5 con los botones resaltados en amarillo. En la superficie del controlador se encuentran los botones de flecha arriba, abajo, izquierda y derecha a la izquierda, y los botones X, A, B, Y en sentido horario desde las 12 en punto a la derecha. En la parte posterior del controlador se encuentran L1, L2, R1 y R2 a la izquierda y derecha respectivamente.

Acceso#

The controller class provides the following button objects. Each object is an instance of the button class.

Objeto

Ejemplo de uso

Descripción

ButtonA

Controller.ButtonA.pressing()

El botón A.

ButtonB

Controller.ButtonB.pressing()

El botón B.

ButtonX

Controller.ButtonX.pressing()

El botón X.

ButtonY

Controller.ButtonY.pressing()

El botón Y.

ButtonDown

Controller.ButtonDown.pressing()

El botón Abajo.

ButtonUp

Controller.ButtonUp.pressing()

El botón Arriba.

ButtonLeft

Controller.ButtonLeft.pressing()

El botón izquierdo.

ButtonRight

Controller.ButtonRight.pressing()

El botón derecho.

ButtonL1

Controller.ButtonL1.pressing()

El botón L1.

ButtonL2

Controller.ButtonL2.pressing()

El botón L2.

ButtonR1

Controller.ButtonR1.pressing()

El botón R1.

ButtonR2

Controller.ButtonR2.pressing()

El botón R2.

Notas#

  • Before using a button member function, create a controller object.

// Create a Controller object
controller Controller = controller();

Funciones de los miembros#

The button class includes the following member functions:

Obtenido: lee el estado del botón.

  • pressing — Returns whether the button is being pressed.

Funciones de devolución de llamada: ejecutan funciones cuando se producen eventos de botón.

  • pressed — Registers a function to run when the button is pressed.

  • released — Registers a function to run when the button is released.

Adquiridor#

prensado#

pressing returns whether the button is currently being pressed.

Función disponible

bool pressing() const;

Parámetros

Esta función no tiene parámetros.

Valor de retorno

Devuelve un valor booleano.

  • true — The button is being pressed.

  • false — The button is not being pressed.

Ejemplo

// Turn right while L1 is pressed
while (true) {
  if (Controller.ButtonL1.pressing()) {
    Drivetrain.turn(right);
  }
  else {
    Drivetrain.stop();
  }

  wait(20, msec);
}

Devoluciones de llamada#

apretado#

pressed registers a function that runs when the button is pressed.

Función disponible

void pressed(void (* callback)(void)) const;

Parámetro

Tipo

Descripción

callback

void (*)(void)

Una función que se ejecuta al pulsar el botón.

Valor de retorno

Esta función no devuelve ningún valor.

Ejemplo

Define the callback function outside of main.

// Drive forward when A is pressed
void driveForward() {
  Drivetrain.driveFor(forward, 100, mm);
}

Register the callback inside main.

int main() {
  vexcodeInit();

  // Run driveForward when A is pressed
  Controller.ButtonA.pressed(driveForward);
}

liberado#

released registers a function that runs when the button is released.

Función disponible

void released(void (* callback)(void)) const;

Parámetro

Tipo

Descripción

callback

void (*)(void)

Una función que se ejecuta cuando se suelta el botón.

Valor de retorno

Esta función no devuelve ningún valor.

Ejemplo

Define the callback function outside of main.

// Stop the drivetrain when A is released
void stopDriving() {
  Drivetrain.stop();
}

Register the callback inside main.

int main() {
  vexcodeInit();

  // Run stopDriving when A is released
  Controller.ButtonA.released(stopDriving);
}