Button#

The available buttons on a V5 Controller are as follows:

V5 Controller

  • ButtonA - The A button.
  • ButtonB - The B button.
  • ButtonX - The X button.
  • ButtonY - The Y button.
  • ButtonDown - The Down button.
  • ButtonUp - The Up button.
  • ButtonLeft - The Left button.
  • ButtonRight - The Right button.
  • ButtonL1 - The L1 button.
  • ButtonL2 - The L2 button.
  • ButtonR1 - The R1 button.
  • ButtonR2 - The R2 button.

pressed()#

The pressed(callback) method registers a function to be called when a button is pressed.

Parameter

Description

callback

A function that will be called when the button is pressed.

Returns: An instance of the Event class.

// Define the buttonPressed function with a void return
// type, showing it doesn't return a value.
void buttonPressed() {
  // The Brain will print that a controller button was
  // pressed on the Brain's screen.
  Brain.Screen.print("controller button pressed");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run buttonPressed when the 'A' controller button is pressed.
  Controller.ButtonA.pressed(buttonPressed);
}

released()#

The released(callback, arg) method registers a function to be called when a button is released.

Parameter

Description

callback

A function that will be called when the button is released.

arg

Optional. A parameter to pass to the callback function.

Returns: An instance of the Event class.

// Define the buttonReleased function with a void return
// type, showing it doesn't return a value.
void buttonReleased() {
  // The Brain will print that a controller button was
  // released on the Brain's screen.
  Brain.Screen.print("controller button released");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run buttonReleased when the 'A' controller button is released.
  Controller.ButtonA.released(buttonReleased);
}

pressing()#

The pressing() method returns whether a button is currently being pressed.

Returns: True if the button is currently being pressed. False if it is not currently being pressed.