Controller#

Introduction#

The IQ (2nd gen) Brain can connect to either an IQ (2nd gen) or IQ (1st gen) Controller. Both controllers have two analog joysticks and multiple buttons that the Brain can use to detect movements and presses.

For the examples below, the configured Distance Sensors will be named Controller, and will be used in all subsequent examples throughout this API documentation when referring to Controller class methods.

Below is a list of available methods:

Actions - Enable or disable the controller.

Getters - Return values from controller joysticks and buttons.

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

  • position – Returns the position of the joystick’s specified axis.

Callback – Interact with the controller through callback methods.

  • pressed – Calls a function when the specified button is pressed.

  • released – Calls a function when the specified button is released.

  • changed – Calls a function when the joystick’s axis changes.

Constructors – Manually initialize the Controller.

Actions#

RemoteControlCodeEnabled#

RemoteControlCodeEnabled is a variable that can be set to a Boolean that enables or disables Controller configured actions from the Devices menu. The controller is enabled by default. It can be set to either of the following:

  • true — Enable Controller configured actions.

  • false — Disable Controller configured actions.

Usage:
RemoteControlCodeEnabled = false;

// Example coming soon

Getters#

pressing#

pressing returns an integer indicating whether a specific button on the controller is currently being pressed. This method must be called on a specific button object, such as ButtonEDown (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 ten available button objects can be used with this method, as shown below:

Button

Command

ButtonEDown

Controller.ButtonEDown.pressing() — The E Down button

ButtonEUp

Controller.ButtonEUp.pressing() — The E Up button

ButtonFDown

Controller.ButtonFDown.pressing() — The F Down button

ButtonFUp

Controller.ButtonFUp.pressing() — The F Up button

ButtonL3

Controller.ButtonL3.pressing() — The Left Joystick button
IQ (2nd gen) Controller only

ButtonLDown

Controller.ButtonLDown.pressing() — The L Down button

ButtonLUp

Controller.ButtonLUp.pressing() — The L Up button

ButtonR3

Controller.ButtonR3.pressing() — The Right Joystick button
IQ (2nd gen) Controller only

ButtonRDown

Controller.ButtonRDown.pressing() — The R Down button

ButtonRUp

Controller.ButtonRUp.pressing() — The R Up button

settings

Parameters

Description

This method has no parameters.

// Example coming soon

position#

position returns the position of the joystick’s specified axis as an integer from –100 to 100, representing a percentage. This method must be called on a specific axis object, such as AxisA (see full list of axis objects below).

Usage:
One of four available axes can be used with this method, as shown below:

Axis

Command

AxisA

Controller.AxisA.position() — The Left Joystick’s vertical axis

AxisB

Controller.AxisB.position() — The Left Joystick’s horizontal axis

AxisC

Controller.AxisC.position() — The Right Joystick’s horizontal axis

AxisD

Controller.AxisD.position() — The Right Joystick’s vertical axis

settings

Parameters

Description

This method has no parameters.

// Example coming soon

Callback#

pressed#

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

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

Button

Command

ButtonEDown

Controller.ButtonEDown.pressed(callback); — The E Down button

ButtonEUp

Controller.ButtonEUp.pressed(callback); — The E Up button

ButtonFDown

Controller.ButtonFDown.pressed(callback); — The F Down button

ButtonFUp

Controller.ButtonFUp.pressed(callback); — The F Up button

ButtonL3

Controller.ButtonL3.pressed(callback); — The Left Joystick button
IQ (2nd gen) Controller only

ButtonLDown

Controller.ButtonLDown.pressed(callback); — The L Down button

ButtonLUp

Controller.ButtonLUp.pressed(callback); — The L Up button

ButtonR3

Controller.ButtonR3.pressed(callback); — The Right Joystick button
IQ (2nd gen) Controller only

ButtonRDown

Controller.ButtonRDown.pressed(callback); — The R Down button

ButtonRUp

Controller.ButtonRUp.pressed(callback); — The R Up button

Parameter

Description

callback

The callback function to be called when the specified button is pressed.

// Example coming soon

released#

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

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

Button

Command

ButtonEDown

Controller.ButtonEDown.released(callback); — The E Down button

ButtonEUp

Controller.ButtonEUp.released(callback); — The E Up button

ButtonFDown

Controller.ButtonFDown.released(callback); — The F Down button

ButtonFUp

Controller.ButtonFUp.released(callback); — The F Up button

ButtonL3

Controller.ButtonL3.released(callback); — The Left Joystick button
IQ (2nd gen) Controller only

ButtonLDown

Controller.ButtonLDown.released(callback); — The L Down button

ButtonLUp

Controller.ButtonLUp.released(callback); — The L Up button

ButtonR3

Controller.ButtonR3.released(callback); — The Right Joystick button
IQ (2nd gen) Controller only

ButtonRDown

Controller.ButtonRDown.released(callback); — The R Down button

ButtonRUp

Controller.ButtonRUp.released(callback); — The R Up button

Parameter

Description

callback

The callback function to be called when the specified button is released.

// Example coming soon

changed#

changed registers a function to be called when the joystick’s position changes. This method must be called on a specific axis object, such as AxisA (see full list of axis objects below).

Usage:
One of four available axes can be used with this method, as shown below:

Axis

Command

AxisA

Controller.AxisA.changed(callback); — The Left Joystick’s vertical axis

AxisB

Controller.AxisB.changed(callback); — The Left Joystick’s horizontal axis

AxisC

Controller.AxisC.changed(callback); — The Right Joystick’s horizontal axis

AxisD

Controller.AxisD.changed(callback); — The Right Joystick’s vertical axis

settings

Parameters

Description

callback

The callback function to be called when the specified axis’s position changes.

// Example coming soon

Constructors#

controller#

controller creates a controller object.

Usage:
controller Controller = controller();

Parameter

Description

This method has no parameters.

// Example coming soon