Controller#
Introduction#
The V5 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.
Derived Classes#
The controller class provides the following derived classes:
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#
Parameter |
Type |
Description |
|---|---|---|
|
|
The type of controller being created:
|
Notes#
Only one
primaryand onepartnercontroller may exist in a single project.
Example#
// Create a V5 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 Functionsvoid rumble(
const char *str );
Parameter |
Type |
Description |
|---|---|---|
|
|
A string consisting of dots and dashes that represent the rumble pattern. |
This function does not return a value.
Examples// Short-short-long pattern
Controller1.rumble("..-");
installed#
Checks whether the controller is installed/connected.
Available Functionsbool installed();
This function does not accept any parameters.
Return ValuesReturns 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 V5 provides a global variable that controls the execution of controller-configured actions.
RemoteControlCodeEnabled#
Enables or disables controller-configured actions defined in the Devices configuration.
AssignmentRemoteControlCodeEnabled = false;
true— Controller-configured actions are enabled.false— Controller-configured actions are disabled.
Controller-configured actions are enabled by default.
// 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;