Controller#

The V5 Controller allows users to control and customize behaviors for their robot or display messages on the Controller’s screen.

Below is a list of available blocks:

Values – Read button states and joystick positions.

Actions – Rumble the controller and enable or disable configured Controller functions.

Events – Run code when a button is pressed or joystick is moved.

Screen – Display text and numbers on the Controller’s screen.

Values#

Controller pressed?#

The Controller pressed? block returns a Boolean indicating whether a specific button on the controller is currently pressed.

  • True – The specified button on the controller is being pressed.

  • False – The specified button on the controller is not 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 oclock on the right. On the back side of the controller are L1, L2, R1, and R2 on the left and right sides respectively.

<[Controller1 v] [▲ v] pressed?>

Parameter

Description

device

Which controller to use, configured in the Devices window.

button

Which button to check:

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

Example

  when started
  [Drive forward while X is pressed.]
  forever
  if <[Controller1 v] [X v] pressed?> then
  drive [forward v]
  else
  stop driving

Controller position#

The Controller position block returns how far a joystick is moved along a specific axis from -100 to 100. A value of 0 means the joystick is centered.

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.

  ([Controller1 v] [1 v] position)

Parameter

Description

device

Which controller to use, configured in the Devices window.

axis

Which axis to check:

  • 1
  • 2
  • 3
  • 4

Example

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

Actions#

play rumble#

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

  play rumble [Long v] on [Controller1 v]

Parameter

Description

pattern

The rumble pattern to play on the controller:

  • Long – A singular, long rumble
  • Short – A singular, short rumble
  • Pulse – A pattern of on and off rumbles

device

Which controller to use, configured in the Devices window.

Controller enable/disable#

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

  Controller [Disable v]

Parameter

Description

state

What state to set the connected controllers to:

  • Disable
  • Enable

    when started
    [Disable controller configured actions until drive is done.]
    Controller [Disable v]
    drive [forward v] for (6) [inches v] ▶
    Controller [Enable v]

Events#

when Controller button pressed#

The when Controller button pressed block runs the attached stack of blocks when a specified 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 oclock on the right. On the back side of the controller are L1, L2, R1, and R2 on the left and right sides respectively..

  when [Controller1 v] button [▲ v] [pressed v] :: hat events

Parameter

Description

device

Which controller to use, configured in the Devices window.

button

Which button to check:

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

state

When the attached stack of blocks will be run:

  • pressed
  • released

Example

  when [Controller1 v] button [Y v] [pressed v] :: hat events
  [Drive forward 50 mm whenever the Y button is pressed]
  drive [forward v] for [200] [mm v] ▶

when Controller axis changed#

The when Controller axis changed block runs the attached stack of blocks whenever the value of a specified joystick axis changes.

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 [Controller1 v] axis [1 v] 
  changed :: hat events

Parameter

Description

device

Which controller to use, configured in the Devices window.

axis

Which axis to check:

  • 1
  • 2
  • 3
  • 4

Example

  when [Controller1 v] axis [3 v] changed :: hat events
  [Move forward when left joystick is up, backwards if down.]
  if <([Controller1 v] [3 v] position) [math_greater_than v] [0]> then
  drive [forward v]
  else if <([Controller1 v] [3 v] position) [math_less_than v] [0]> then
  drive [reverse v]
  else
  stop driving

Screen#

The V5 Controller has access to 3 rows and 19 columns to print on.

A screenshot of the V5 Controller screen, showing the rows and columns in the printable area. Row 1 Column 1 starts at the upper left corner and row 3, column 19 are in the lower right corner.

set cursor on Controller#

The set cursor on Controller block sets the cursor to a specific row and column on the controller’s screen. The controller screen has 3 rows and 19 columns.

A screenshot of the V5 Controller screen, showing the rows and columns in the printable area. Row 1 Column 1 starts at the upper left corner and row 3, column 19 are in the lower right corner.

  set cursor to row [1] column [1] on [Controller1 v]

Parameter

Description

row

The row of the cursor from 1 to 3.

column

The column of the cursor from 1 to 19.

device

Which controller to use, configured in the Devices window.

Example

  when started
  [Clear the screen to prepare for printing.]
  clear [Controller1 v]
  set cursor to row [1] column [1] on [Controller1 v]
  print [Hello!] on [Controller1 v] ▶

set cursor to next row on Controller#

The set cursor to next row on Controller block sets the cursor to the next row on the controller’s screen.

  set cursor to next row on [Controller1 v]

Parameter

Description

device

Which controller to use, configured in the Devices window.

Example

  when started
  [Clear the screen to prepare for printing.]
  clear [Controller1 v]
  set cursor to row [1] column [1] on [Controller1 v]
  print [Row 1] on [Controller1 v] ▶
  set cursor to next row on [Controller1 v]
  print [Row 2] on [Controller1 v] ▶

set print precision on Controller#

The set print precision on Controller block sets how many decimal places are shown when printing numbers on the controller’s screen.

  set print precision to [1 v] on [Controller1 v]

Parameter

Description

precision

How many decimals will be shown when numbers are printed:

  • 1
  • 0.1
  • 0.01
  • 0.001
  • All Digits

device

Which controller to use, configured in the Devices window.

Example

  when started
  [Display division with two decimals.]
  set print precision to [0.01 v] on [Controller1 v]
  print ([1] [math_division v] [3]) on [Controller1 v] ▶

clear Controller#

The clear Controller block clears the Controller’s screen.

  clear [Controller1 v]

Parameter

Description

device

Which controller to use, configured in the Devices window.

Example

  when started
  [Clear the screen to prepare for printing.]
  clear [Controller1 v]
  set cursor to row [1] column [1] on [Controller1 v]
  print [Hello!] on [Controller1 v] ▶

clear row on Controller#

The clear row on Controller block clears a specified row on the Controller’s screen.

  clear row [1] on [Controller1 v]

Parameter

Description

row

Which row to clear from 1 to 3.

device

Which controller to use, configured in the Devices window.

Example

  when started
  [Clear only one row on the controller.]
  clear [Controller1 v]
  set cursor to row [1] column [1] on [Controller1 v]
  print [I will go!] on [Controller1 v] ▶
  set cursor to next row on [Controller1 v]
  print [I will stay!] on [Controller1 v] ▶
  wait [2] seconds
  clear row [1] on [Controller1 v]