Botón#

Introducción#

The button class is derived from the brain base class and provides access to the EXP Brain’s buttons, allowing your robot to detect when its buttons are pressed and released.

Acceso#

The button class provides three button objects. Each object is an instance of the button class and can be accessed through a brain instance.

Objeto

Ejemplo de uso

Descripción

buttonCheck

Brain.buttonCheck.pressing()

Botón de verificación

buttonLeft

Brain.buttonLeft.pressing()

Botón izquierdo

buttonRight

Brain.buttonRight.pressing()

Botón derecho

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 brain instance must be created, as shown below:

// Create the EXP Brain
brain Brain = brain();

prensado#

Indica si se está presionando un botón cerebral específico en ese momento.

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, por ejemplo:

  • Brain.buttonCheck
  • Brain.buttonLeft
  • Brain.buttonRight
// Turn right while the check button is pressed
while (true) {
    if (Brain.buttonCheck.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 cerebral específico.

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 cerebral, por ejemplo:

  • Brain.buttonCheck
  • Brain.buttonLeft
  • Brain.buttonRight

Define the callback function (outside of int main())

// Drive forward when the right button 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 right button is pressed
  Brain.buttonRight.pressed(driveForward);
}

liberado#

Registra una función de devolución de llamada que se ejecuta cuando se suelta un botón cerebral específico.

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 cerebral, por ejemplo:

  • Brain.buttonCheck
  • Brain.buttonLeft
  • Brain.buttonRight

Define the callback function (outside of int main())

// Drive backward when the left button 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 left button is released
  Brain.buttonLeft.released(backUp);
}