Controller#

Introduction#

The V5 Controller has buttons, two joysticks, a rumble motor, and a screen. Controller blocks can be used to check button presses, read joystick movement, rumble the Controller, enable or disable configured Controller actions, run blocks when Controller events happen, or display text on the Controller screen.

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 available blocks:

Values — Check Controller button status or read joystick position.

Actions — Rumble the Controller, enable/disable configured Controller actions, or run blocks when Controller input changes.

Screen — Display text and numbers on the Controller screen.

Values#

Controller pressed?#

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

The front and back side of the V5 Controller with the buttons highlighted in yellow. On the surface of the controller are up, down, left, and right arrow buttons on the left, and X, A, B, Y buttons clockwise from 12 o'clock on the right. On the back side of the controller are L1, L2, R1, and R2 on the left and right sides respectively.

Controller pressed? Boolean block#
    <[Controller1 v] [▲ v] pressed?>

Parameter

Description

device

The Controller to use, configured in the Devices window.

button

The button to check:

  • X
  • B
  • Y
  • A
  • L1
  • L2
  • R1
  • R2

Example

When started, drives forward while the X button is pressed.#
    when started
    [Drive forward while X is pressed.]
    forever
        if <[Controller1 v] [X 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.

A VEX V5 Controller with the axes around the joysticks labeled. Axis 1 and 2 are around the right joystick, and Axis 3 and 4 are around the left.

Controller position reporter block#
    ([Controller1 v] [1 v] position :: sensing)

Parameter

Description

device

The Controller to use, configured in the Devices window.

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 <([Controller1 v] [3 v] position :: sensing) [math_greater_than v] [0]> then
            drive [forward v]
        else
            stop driving
        end
    end

Actions#

play rumble on controller#

The play rumble on controller stack block plays a rumble pattern on the Controller.

play rumble on controller stack block#
    play rumble [Long v] on [Controller1 v]

Parameter

Description

pattern

The rumble pattern to play on the Controller:

  • Long — one long rumble
  • Short — one short rumble
  • Pulse — a pattern of on and off rumbles

device

The Controller to use, configured in the Devices window.

Example

When the R1 button is pressed, plays a short rumble on the Controller.#
    when [Controller1 v] button [R1 v] [pressed v] :: hat events
    play rumble [Short v] on [Controller1 v]

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 back side of the V5 Controller with the buttons highlighted in yellow. On the surface of the controller are up, down, left, and right arrow buttons on the left, and X, A, B, Y buttons clockwise from 12 o'clock on the right. On the back side of the controller are L1, L2, R1, and R2 on the left and right sides respectively.

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

Parameter

Description

device

The Controller to use, configured in the Devices window.

button

The button to check:

  • X
  • B
  • Y
  • A
  • L1
  • L2
  • R1
  • R2

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 [Controller1 v] 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.

A VEX V5 Controller with the axes around the joysticks labeled. Axis 1 and 2 are around the right joystick, and Axis 3 and 4 are around the left.

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

Parameter

Description

device

The Controller to use, configured in the Devices window.

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 [Controller1 v] 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] ▶

Screen#

set cursor to row column on controller#

The set cursor to row column on controller stack block moves the cursor to a specified row and column on the Controller screen. The next printed value will appear at that position.

set cursor to row column on controller stack block#
    set cursor to row [1] column [1] on [Controller1 v] :: custom-controller-inertial-timer

Parameter

Description

row

The row to move the cursor to on the Controller screen.

column

The column to move the cursor to on the Controller screen.

device

The Controller to use, configured in the Devices window.

Example

When started, prints text at row 2, column 1 on the Controller screen.#
    when started
    [Display a message on row 2.]
    set cursor to row [2] column [1] on [Controller1 v] :: custom-controller-inertial-timer
    print [Ready] on [Controller1 v] ▶ :: custom-controller-inertial-timer

set cursor to next row on controller#

The set cursor to next row on controller stack block moves the cursor to column 1 on the next row of the Controller screen. The next printed value will appear on that row.

set cursor to next row on controller stack block#
    set cursor to next row on [Controller1 v] :: custom-controller-inertial-timer

Parameter

Description

device

The Controller to use, configured in the Devices window.

Example

When started, prints two rows on the Controller screen.#
    when started
    [Display two rows of text.]
    print [Row 1] on [Controller1 v] ▶ :: custom-controller-inertial-timer
    set cursor to next row on [Controller1 v] :: custom-controller-inertial-timer
    print [Row 2] on [Controller1 v] ▶ :: custom-controller-inertial-timer

set print precision on controller#

The set print precision on controller stack block sets how many decimal places are displayed when numbers are printed on the Controller screen. This setting applies to numbers printed after this block is used.

set print precision on controller stack block#
    set print precision to [0.1 v] on [Controller1 v] :: custom-controller-inertial-timer

Parameter

Description

precision

The print precision to use:

  • 1 — no decimal places
  • 0.1 — 1 decimal place
  • 0.01 — 2 decimal places
  • 0.001 — 3 decimal places
  • All Digits — all available decimal places

device

The Controller to use, configured in the Devices window.

Example

When started, displays 1/3 with two decimal places on the Controller screen.#
    when started
    [Display 1/3 with two decimals.]
    set print precision to [0.01 v] on [Controller1 v] :: custom-controller-inertial-timer
    print ([1] [math_division v] [3]) on [Controller1 v] ▶ :: custom-controller-inertial-timer

clear controller#

The clear controller stack block clears all rows on the Controller screen and moves the cursor back to the first row.

clear controller stack block#
    clear [Controller1 v] :: custom-controller-inertial-timer

Parameter

Description

device

The Controller to use, configured in the Devices window.

Example

When started, prints text, waits, then clears the Controller screen.#
    when started
    [Clear the Controller screen after printing.]
    print [This will disappear...] on [Controller1 v] ▶ :: custom-controller-inertial-timer
    wait [2] seconds
    clear [Controller1 v] :: custom-controller-inertial-timer

clear row on controller#

The clear row on controller stack block clears a single row on the Controller screen.

clear row on controller stack block#
    clear row [1] on [Controller1 v] :: custom-controller-inertial-timer

Parameter

Description

row

The row to clear on the Controller screen.

device

The Controller to use, configured in the Devices window.

Example

When started, clears row 1 on the Controller screen.#
    when started
    [Clear one row on the Controller screen.]
    print [Row 1] on [Controller1 v] ▶ :: custom-controller-inertial-timer
    set cursor to next row on [Controller1 v] :: custom-controller-inertial-timer
    print [Row 2] on [Controller1 v] ▶ :: custom-controller-inertial-timer
    wait [2] seconds
    clear row [1] on [Controller1 v] :: custom-controller-inertial-timer