Controller#

Introduction#

The EXP Controller is represented by the controller class. You create a controller object and can access joystick input, button states, and screen functionality through its derived classes.

EXP is compatible with the V5 Controller, see the V5 Controller API for more information.

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.

Class 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 );

Class Destructor#

~controller();

Parameters#

范围

Type

描述

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#

Rumbles the controller by a pattern defined by the parameter. Dots equal short vibrations, dashes equal long vibrations, and spaces equal pauses.

Available Functions
void rumble(
    const char *str );

Parameters

范围

Type

描述

str

const char *

A string consisting of dots and dashes that represent the rumble pattern.

Return Values

This function does not return a value.

Examples
// Short-short-long pattern
Controller1.rumble("..-");

installed#

Checks whether the controller is installed/connected.

Available Functions
bool installed();

Parameters

This function does not accept any parameters.

Return Values

Returns a Boolean indicating whether the controller is installed.

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

Global Variables#

When one or more controllers are configured in the Devices window, VEXcode EXP provides a global variable that controls the execution of controller-configured actions.

RemoteControlCodeEnabled#

Enables or disables controller-configured actions defined in the Devices configuration.

Assignment
RemoteControlCodeEnabled = false;

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 the controller configured actions
    } else if (Controller1.ButtonA.pressing()) {
        break;
    } else {
        Drivetrain.stop();
    }
    wait(20, msec);
}
RemoteControlCodeEnabled = true;