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.

Sensing – Read current input from the controller.

Events#

when controller button#

The when controller button block activates the attached stack of blocks when the button is being pressed or released.

Angelo image here

    when Controller button [E Up v] [pressed v] :: hat events

Parameters

Description

button

The button to check for a press or release:

  • E Up
  • E Down
  • F Up
  • F Down
  • L Up
  • L Down
  • R Up
  • R Down
  • L3
  • R3

button status

Specifies whether to trigger the attached stack of blocks when the button is:

  • pressed
  • released

Example

    when Controller button [R Up v] [pressed v] :: hat events
    [Turn when a button is pressed.]
    turn [right v] for (90) degrees ▶

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:

  • A
  • B
  • C
  • D

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 button pressed?#

The controller button pressed? block returns an integer indicating whether a specific controller button is being pressed.

  • 0 - The controller button is not being pressed.

  • 1 - The controller button is being pressed.

Controller button image here

    <Controller [E Up v] pressed?>

Parameters

Description

button

The button to check for a press or release:

  • E Up
  • E Down
  • F Up
  • F Down
  • L Up
  • L Down
  • R Up
  • R Down
  • L3
  • R3

Example

    when started :: hat events
    [Move forward when the R Up button is pressed.]
    forever
    if <Controller [R Up v] pressed?> then
    drive [forward v]
    else
    stop driving

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:

  • A
  • B
  • C
  • D

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:

  • Disable
  • Enable

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]