Controller#

Introduction#

The VEX EXP 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.

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:

Values — Check controller button status or read joystick position.

Actions — Enable or disable configured controller actions, or run blocks when controller input changes.

Values#

Controller pressed?#

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

The front and top side of the EXP Controller with the joysticks, arrow buttons, and action buttons highlighted in yellow. On the surface of the controller are two joysticks on the left and right, with up and down arrow buttons on the left and A and B buttons on the right. On the top of the controller are L1 and L2 on the left side and R1 and R2 on the right side.

Controller pressed? Boolean block#
    <Controller [L1 v] pressed?>

Parameter

Description

button

The button to check:

  • L1
  • L2
  • L3
  • R1
  • R2
  • R3
  • A
  • B

Example

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

Controller position#

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

The front side of the EXP Controller with the joystick axis numbers highlighted in red. On the surface of the controller, the left joystick is labeled as Axis 4 for left and right movement and Axis 3 for up and down movement, while the right joystick is labeled as Axis 1 for left and right movement and Axis 2 for up and down movement.

Controller position reporter block#
    (Controller [1 v] position)

Parameter

Description

axis

The joystick axis to report:

  • 1 — right joystick horizontal axis
  • 2 — right joystick vertical axis
  • 3 — left joystick vertical axis
  • 4 — left joystick horizontal axis

Example

When started, drives forward while the left joystick is pushed up.#
    when started
    [Drive forward while the left joystick is pushed up.]
    forever
        if <(Controller [3 v] position) [math_greater_than v] [0]> then
            drive [forward v]
        else
            stop driving
        end
    end

Actions#

Controller enable/disable#

The Controller enable/disable stack block enables or disables Controller configured actions from the Devices menu for all connected controllers.

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]

when Controller button pressed#

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

The front and top side of the EXP Controller with the joysticks, arrow buttons, and action buttons highlighted in yellow. On the surface of the controller are two joysticks on the left and right, with up and down arrow buttons on the left and A and B buttons on the right. On the top of the controller are L1 and L2 on the left side and R1 and R2 on the right side.

when Controller button pressed Hat block#
    when Controller button [L1 v] [pressed v] :: hat events

Parameter

Description

button

The button to check:

  • L1
  • L2
  • L3
  • R1
  • R2
  • R3
  • A
  • B

button status

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

Example

When the R1 button is pressed, drives forward for 200 millimeters.#
    when Controller button [R1 v] [pressed v] :: hat events
    [Drive forward when R1 is pressed.]
    drive [forward v] for (200) [mm v] ▶

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 front side of the EXP Controller with the joystick axis numbers highlighted in red. On the surface of the controller, the left joystick is labeled as Axis 4 for left and right movement and Axis 3 for up and down movement, while the right joystick is labeled as Axis 1 for left and right movement and Axis 2 for up and down movement.

when Controller axis is changed Hat block#
    when Controller axis [1 v] is changed :: hat events

Parameter

Description

axis

The joystick axis to check:

  • 1 — right joystick horizontal axis
  • 2 — right joystick vertical axis
  • 3 — left joystick vertical axis
  • 4 — left joystick horizontal axis

Example

When the joystick’s position changes along Controller axis 3, drives forward for 200 millimeters.#
    when Controller axis [3 v] is changed :: hat events
    [Drive forward when the joystick's position changes along axis 3.]
    drive [forward v] for (200) [mm v] ▶