Controller#
Introduction#
The Controller category includes blocks for detecting and responding to input from the VEX IQ (2nd generation) Controller. These blocks allow your robot to react to button presses, monitor joystick positions, and control how input mappings are applied during a project.
Below is a list of available blocks:
Events – Run code in response to user input.
when controller button – Runs a stack when a specific controller button is pressed or released.
when controller axis is changed – Runs a stack when a joystick axis is moved.
Sensing – Read current input from the controller.
controller button pressed? – Returns a Boolean indicating whether a button is currently pressed.
controller axis position – Returns the current joystick axis position from –100 to 100.
controller enable/disable – Temporarily enables or disables controller actions.
Events#
when controller axis is changed#
The when controller axis is changed block activates the attached stack of blocks when the axis is being changed.
when Controller axis [A v] is changed :: hat events
Parameters |
Description |
---|---|
axis |
The axis to check for change:
|
Example
when Controller axis [D v] is changed :: hat events
[Move forward when right joystick is moved.]
drive [forward v] for (200) [mm v] ▶
Sensing#
controller axis position#
The controller axis position block returns the position of the joystick along a specified axis as an integer from -100 to 100.
(Controller [A v] position)
Parameters |
Description |
---|---|
axis |
The axis to check for change:
|
Example
when started :: hat events
[Turn depending on the position of the right joystick.]
forever
if <(Controller [C v] position) < [0]> then
turn [left v]
else if <(Controller [C v] position) > [0]> then
turn [right v]
else
stop driving
controller enable/disable#
The controller enable/disable block is used to enable or disable Controller configured actions from the Devices menu.
Controller [Disable v]
Parameters |
Description |
---|---|
state |
What state to set the controller to:
|
Example
when started :: hat events
[Disable controller configured actions until drive is done.]
Controller [Disable v]
drive [forward v] for (6) [inches v] ▶
Controller [Enable v]