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.
Below is a list of all available methods:
Methods – Control the behavior and input of the controller.
.pressed – Calls a function when the specified button is pressed.
.released – Calls a function when the specified button is released.
.pressing – Returns whether the specified button is being pressed.
.position – Returns the position of the joystick’s specified axis.
.changed – Calls a function when the joystick’s axis changes.
Constructors – Manually initialize and configure the controller.#
Controller – Create a controller.
.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 the available button objects can be used with this method, as shown below:
Button |
Command |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parameters |
Description |
---|---|
callback |
A function that is previously defined to execute when the specified button is being pressed. |
arg |
Optional. A tuple containing arguments to pass to the callback function. See Using Events with Parameters for more information. |
# 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 the available button objects can be used with this method, as shown below:
Button |
Command |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parameters |
Description |
---|---|
callback |
A function that is previously defined to execute when the specified button is released. |
arg |
Optional. A tuple containing arguments to pass to the callback function. See Using Events with Parameters for more information. |
# Example coming soon
.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 five available button objects can be used with this method, as shown below:
Button |
Command |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
---|---|
|
|
|
|
|
|
|
|
Parameters |
Description |
---|---|
This method has no parameters. |
# 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 |
---|---|
|
|
|
|
|
|
|
|
Parameters |
Description |
---|---|
callback |
A function that is previously defined to execute when the axis’ value changes. |
arg |
Optional. A tuple containing arguments to pass to the callback function. See Using Events with Parameters for more information. |
# Function to display an emoji when the joystick is moved
def move_joystick():
robot.screen.show_emoji(CONFUSED)
# Run the function when the joystick is moved up or down
controller.axis1.changed(move_joystick)
Constructors#
Constructors are used to manually create Controller
objects, which are necessary for configuring a controller outside of VEXcode.
For the examples below, the configured controller will be named controller
and will be used in all subsequent examples throughout this API documentation when referring to Controller
class methods.
Controller#
Controller
creates a controller.
Usage:
Controller()
Parameters |
Description |
---|---|
This constructor has no parameters. |
# Example coming soon