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.

Vista frontal y posterior del mando IQ de segunda generación con todos los botones resaltados en amarillo. La superficie del mando contiene dos botones de joystick en las esquinas superior izquierda y derecha, con E arriba y abajo debajo del joystick izquierdo y F arriba y abajo debajo del derecho. En la parte posterior del mando se encuentran L arriba y abajo y R arriba y abajo en los lados izquierdo y derecho 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

ButtonEDown

Controller.ButtonEDown.pressing()

El botón E ▼.

ButtonEUp

Controller.ButtonEUp.pressing()

El botón E ▲.

ButtonFDown

Controller.ButtonFDown.pressing()

El botón F ▼.

ButtonFUp

Controller.ButtonFUp.pressing()

El botón F ▲.

ButtonL3

Controller.ButtonL3.pressing()

El botón Joystick izquierdo. Solo para el mando IQ (2.ª generación).

ButtonLDown

Controller.ButtonLDown.pressing()

El botón L ▼.

ButtonLUp

Controller.ButtonLUp.pressing()

El botón L ▲.

ButtonR3

Controller.ButtonR3.pressing()

El botón Joystick derecho. Solo para el mando IQ (2.ª generación).

ButtonRDown

Controller.ButtonRDown.pressing()

El botón R ▼.

ButtonRUp

Controller.ButtonRUp.pressing()

El botón R ▲.

Notas#

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

  • ButtonL3 and ButtonR3 are only available on the IQ (2nd gen) Controller.

// 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 R Up is pressed
while (true) {
  if (Controller.ButtonRUp.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 F Up is pressed
void driveForward() {
  Drivetrain.driveFor(forward, 100, mm);
}

Register the callback inside main.

int main() {
  vexcodeInit();

  // Run driveForward when F Up is pressed
  Controller.ButtonFUp.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 F Up is released
void stopDriving() {
  Drivetrain.stop();
}

Register the callback inside main.

int main() {
  vexcodeInit();

  // Run stopDriving when F Up is released
  Controller.ButtonFUp.released(stopDriving);
}