Brain#

Introduction#

The VEX IQ (2nd Gen) Brain Sensing category offers methods for interacting with the Brain’s buttons and connected battery.

This page uses Brain as the example Brain name. Replace it with your own configured name as needed.

Below is a list of all available methods:

Actions – Interact with the VEX IQ (2nd Gen) Buttons.

  • 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.

Getters – Return data from the buttons and battery.

  • capacity – Returns the remaining battery capacity.

  • pressing – Returns whether the specified button is being pressed.

  • voltage – Returns the battery voltage.

  • current – Returns the battery current.

Constructors – Manually initialize the Brain.

  • brain – Create a Brain.

Actions#

pressed#

pressed registers a function to be called when a specific button on the Brain is pressed. This method must be called on a specific button object, such as buttonCheck – (see full list of button objects below).

Usage:
One of the three available button objects can be used with this method, as shown below:

Button

Command

buttonCheck

Brain.buttonCheck.pressed(callback); — The Check button

buttonLeft

Brain.buttonLeft.pressed(callback); — The Left button

buttonRight

Brain.buttonRight.pressed(callback); — The Right button

Parameters

Description

callback

A function that is previously defined to execute when the specified button is being pressed.

// Display text with this function
void onCheckPressed() {
  Brain.Screen.clearScreen();
  Brain.Screen.print("Button pressed!");
}

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

   // Call the onCheckPressed when Check button is pressed
  Brain.buttonCheck.pressed(onCheckPressed);
}

released#

released registers a function to be called when a specific button on the Brain is released. This method must be called on a specific button object, such as buttonCheck – (see full list of button objects below).

Usage:
One of the three available button objects can be used with this method, as shown below:

Button

Command

buttonCheck

Brain.buttonCheck.released(callback); — The Check button

buttonLeft

Brain.buttonLeft.released(callback); — The Left button

buttonRight

Brain.buttonRight.released(callback); — The Right button

Parameters

Description

callback

A function that is previously defined to execute when the specified button is being pressed.

// Display text with this function
void onCheckReleased() {
  Brain.Screen.clearScreen();
  Brain.Screen.print("Button released!");
}

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

  // Call the onCheckReleased when Check button is released
  Brain.buttonCheck.released(onCheckReleased);
}

Getters#

capacity#

capacity returns the remaining battery capacity of the Brain as a percentage.

Usage:
Brain.Battery.capacity()

Parameters

Description

This method has no parameters.

pressing#

pressing returns a Boolean indicating whether a specific button on the Brain is currently being pressed. This method must be called on a specific button object, such as buttonCheck (see full list of button objects below).

  • 1 - The specified button is being pressed.

  • 0 - The specified button is not being pressed.

Usage:
One of three available button objects can be used with this method, as shown below:

Button

Command

buttonCheck

Brain.buttonCheck.pressing() — The Check button

buttonLeft

Brain.buttonLeft.pressing() — The Left button

buttonRight

Brain.buttonRight.pressing() — The Right button

Parameters

Description

This method has no parameters.

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

  // Show if Check button is pressed
  while (true) {
    Brain.Screen.clearScreen();
    Brain.Screen.setCursor(1, 1);
    if (Brain.buttonCheck.pressing()) {
      Brain.Screen.print("Pressed");
    } else {
      Brain.Screen.print("Not pressed");
    }
    wait(100, msec);
  }
}

voltage#

voltage returns the Brain’s battery voltage in volts.

Usage:
Brain.Battery.voltage()

Parameters

Description

This method has no parameters.

current#

current returns the Brain’s battery current in amps.

Usage:
Brain.Battery.current()

Parameters

Description

This method has no parameters.

Constructors#

brain#

brain creates an object of the brain Class.

Usage:
brain Brain;

Parameter

Description

This constructor has no parameters.

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

  // Create a new Brain object
  brain MyBrain;
}