Controller#

Introduction#

The VEX IQ (2nd gen) Controller has buttons and two joysticks. Controller blocks can be used to check button presses, read joystick movement, enable or disable configured controller actions, or run blocks when controller events happen.

The IQ (2nd gen) Brain can connect to either an IQ (2nd gen) or IQ (1st gen) Controller. An IQ (1st gen) Controller must have a blue Smart Radio installed.

Configured controller actions are controller behaviors set in the Devices menu. Use the controller enable/disable block to temporarily enable or disable those configured actions during a project.

Below is a list of all blocks:

Booleans — Check controller button status.

Reporters — Read joystick position.

Actions — Enable or disable configured controller actions.

Events — Run blocks when controller input changes.

Booleans#

controller button pressed?#

The controller button pressed? Boolean block returns whether a selected controller button is being pressed.

A front and back side view of the IQ 2nd gen Controller with all buttons highlighted yellow. The surface of the controller contains two joystick buttons in the upper left and right corners, with E up and down below the left joystick and F up and down below the right. On the back of the controller are L up and down and R up and down on the left and right sides respectively.
controller button pressed? Boolean block#
    <Controller [E ▲ v] pressed?>

Parameter

Description

button

The button to check:

  • E ▲
  • E ▼
  • F ▲
  • F ▼
  • L ▲
  • L ▼
  • R ▲
  • R ▼
  • L3
  • R3

Example

When started, drives forward while the R ▲ button is pressed.#
    when started
    [Move forward while the R ▲ button is pressed.]
    forever
        if <Controller [R ▲ v] pressed?> then
            drive [forward v]
        else
            stop driving
        end
    end

Reporters#

controller axis position#

The controller axis position reporter block returns the joystick position along a selected axis as a number from -100 to 100.

The IQ 2nd gen Controller with the four joystick axes highlighted. On the left joystick, Axis A is vertical and Axis B is horizontal. On the right joystick, Axis C is horizontal and Axis D is vertical.
controller axis position reporter block#
    (Controller [A v] position)

Parameter

Description

axis

The joystick axis to report:

  • A — left joystick vertical axis
  • B — left joystick horizontal axis
  • C — right joystick horizontal axis
  • D — right joystick vertical axis

Example

When started, turns depending on the position of the right joystick.#
    when started
    [Turn depending on the position of the right joystick.]
    forever
        if <(Controller [C v] position) [math_less_than v] [0]> then
            turn [left v]
        else if <(Controller [C v] position) [math_greater_than v] [0]> then
            turn [right v]
        else
            stop driving
        end
    end

Actions#

controller enable/disable#

The controller enable/disable stack block enables or disables controller actions configured in the Devices menu.

controller enable/disable stack block#
    Controller [Disable v]

Parameter

Description

state

The controller configured action state: Disable or Enable.

Example

When started, disables configured controller actions while the robot drives forward.#
    when started
    [Disable controller configured actions until the drive movement is done.]
    Controller [Disable v]
    drive [forward v] for (6) [inches v] ▶
    Controller [Enable v]

Events#

when controller button#

The when controller button Hat block runs the attached stack when a selected controller button is pressed or released.

A front and back side view of the IQ 2nd gen Controller with all buttons highlighted yellow. The surface of the controller contains two joystick buttons in the upper left and right corners, with E up and down below the left joystick and F up and down below the right. On the back of the controller are L up and down and R up and down on the left and right sides respectively.
when controller button Hat block#
    when Controller button [E ▲ v] [pressed v]

Parameter

Description

button

The button to check:

  • E ▲
  • E ▼
  • F ▲
  • F ▼
  • L ▲
  • L ▼
  • R ▲
  • R ▼
  • L3
  • R3

button status

The button event that triggers the attached stack: pressed or released.

Example

When the R ▲ button is pressed, turns the robot right for 90 degrees.#
    when Controller button [R ▲ v] [pressed v]
    [Turn when the R ▲ button is pressed.]
    turn [right v] for (90) degrees ▶

when controller axis is changed#

The when controller axis is changed Hat block runs the attached stack when a joystick’s position changes along the selected axis.

The IQ 2nd gen Controller with the four joystick axes highlighted. On the left joystick, Axis A is vertical and Axis B is horizontal. On the right joystick, Axis C is horizontal and Axis D is vertical.
when controller axis is changed Hat block#
    when Controller axis [A v] is changed

Parameter

Description

axis

The joystick axis to check:

  • A — left joystick vertical axis
  • B — left joystick horizontal axis
  • C — right joystick horizontal axis
  • D — right joystick vertical axis

Example

When the joystick’s position changes along controller axis C, turns the robot right for 90 degrees.#
    when Controller axis [C v] is changed
    [Turn when the joystick's position changes along axis C.]
    turn [right v] for (90) degrees ▶