Controller#

Introduction#

The controller class represents a VEX EXP Controller connected to the EXP Brain. A controller object can be used to access joystick axis values, read button states, register button or joystick callbacks, make the controller rumble, and check whether the controller is connected.

VEX EXP is compatible with the V5 Controller. See the V5 Controller API for more information.

When one or more controllers are configured in the Devices window, VEXcode EXP also provides RemoteControlCodeEnabled. This global variable enables or disables controller actions configured in the Devices menu.

Derived Classes#

The controller class provides the following derived classes:

  • Axis - Provides access to joystick axis input values and change events.

  • Button - Provides access to button state and button event callbacks.

Constructors#

1 - Creates a controller using the primary controller type. Typically used when a single controller is connected.

controller();

2 - Creates a controller for the specified controller type. Used when two controllers are connected.

controller(
    controllerType id );

Available Functions

controller();

controller(controllerType id);

Parameter

Type

Description

id

controllerType

Optional. The controller type to create: primary for the primary controller connected to the Brain or partner for the second controller connected to the Brain.

Notes

Only one primary controller and one partner controller can be created in a single project.

Example

// Create the primary controller
controller Controller1 = controller();

// Create a partner controller
controller Controller2 = controller(partner);

Destructor#

~controller#

~controller destroys the controller object and releases associated resources.

Available Function

~controller();

Parameters#

Parameter

Type

Description

id

controllerType

The type of controller being created:

  • primary - The primary controller connected to the Brain.
  • partner - The partner (second) controller connected to the Brain.

Notes#

  • Only one primary and one partner controller may exist in a single project.

Example#

// Create an EXP controller instance
controller Controller = controller();

Member Functions#

The controller class includes the following member functions:

  • rumble - Rumbles the controller using a pattern.

  • installed - Checks whether the controller is connected to the brain.

rumble#

rumble makes the controller vibrate using a pattern. In the pattern string, dots are short vibrations, dashes are long vibrations, and spaces are pauses.

Available Function

void rumble(const char *str);

Parameter

Type

Description

str

const char *

A string made of dots, dashes, and spaces that represent the rumble pattern.

Return Value

This function does not return a value.

Example

// Rumble with a short-short-long pattern
Controller1.rumble("..-");

Getter#

installed#

installed returns whether the controller is connected to the Brain.

Available Function

bool installed();

Parameters

This function does not have parameters.

Return Value

Returns a Boolean value.

  • true - The controller is installed/connected.
  • false - The controller is not installed/connected.

Global Variables#

RemoteControlCodeEnabled#

RemoteControlCodeEnabled enables or disables controller actions configured in the Devices menu. Controller configured actions are enabled by default.

Usage:
RemoteControlCodeEnabled = state;

Value

Description

true

Enables controller configured actions.

false

Disables controller configured actions.

Values
  • true - Controller-configured actions are enabled.
  • false - Controller-configured actions are disabled.
Notes
  • Controller-configured actions are enabled by default.

  • This variable will only work when using VEXcode.

Examples
// Drive forward or backward using the left joystick
RemoteControlCodeEnabled = false;

while (true) {
  if (Controller1.Axis3.position() > 0) {
    Drivetrain.drive(forward);
  }
  else if (Controller1.Axis3.position() < 0) {
    Drivetrain.drive(reverse);
  }
  // Press A to use controller configured actions again
  else if (Controller1.ButtonA.pressing()) {
    break;
  }
  else {
    Drivetrain.stop();
  }

  wait(20, msec);
}

RemoteControlCodeEnabled = true;