Programming With Pictures icon Programming With Pictures — Use camera-detected printed cue cards (direction, pause, start) to record and run stored movement sequences for ARC robots. Try it →
 

Gamepad

Read gamepads and joysticks plugged into the computer ARCx runs on: the sticks and triggers as axes, the buttons, the hat (d-pad), motion sensors and battery, and make them rumble. Controller 0 is the first one plugged in. Standard names such as "LeftX" or "A" work for gamepads; the raw commands read any joystick by number.

Where to find it: type Gamepad. in a JavaScript script, or open the ARCx API view of the script editor and expand Gamepad


Commands

Command What it does
Gamepad.getAccelerometer [x, y, z] in m/s², gravity included.
Gamepad.getAxis Sticks -1 to 1 (up and left are negative), triggers 0 to 1
Gamepad.getAxisNames Lists the axis names the axis commands accept: the X and Y of each stick and the two triggers.
Gamepad.getBattery 0 to 100, or -1 when the controller does not say
Gamepad.getButton True while the button is held
Gamepad.getButtonNames Lists the button names the button commands accept.
Gamepad.getControllerType "Xbox", "PS5", "Switch Pro", "Joystick" and so on
Gamepad.getCount How many controllers are connected
Gamepad.getGyro [x, y, z] in radians per second.
Gamepad.getHat "Centered", "Up", "UpRight", "Right", "DownRight", "Down", "DownLeft", "Left" or "UpLeft"
Gamepad.getHatCount Gets how many hats (the 8-way thumb switches on joysticks) the first controller has.
Gamepad.getName Gets the name of the first controller.
Gamepad.getNames The names of the connected controllers, in index order
Gamepad.getRawAxis -1 to 1
Gamepad.getRawAxisCount Gets how many raw axes the first controller has.
Gamepad.getRawButton Checks whether a raw button on the first controller is held down, by number.
Gamepad.getRawButtonCount Gets how many raw buttons the first controller has.
Gamepad.isConnected Checks whether the first controller is plugged in.
Gamepad.isGamepad False for flight sticks, wheels and unrecognized controllers, which only have raw axes and buttons
Gamepad.rumble Rumble at a strength of 0 to 1 for the milliseconds given
Gamepad.rumbleMotors Rumble the heavy (low) and light (high) motors separately, 0 to 1 each.
Gamepad.setLED Set the light bar colour (0 to 255 each) on controllers that have one
Gamepad.stopRumble Stops the first controller rumbling straight away.
Gamepad.waitForButton Wait for the button to be pressed.

Details

Gamepad.getAccelerometer

[x, y, z] in m/s², gravity included. Turns the sensors on at the first call

Gamepad.getAccelerometer()
Gamepad.getAccelerometer(index)
Value Type What it is
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: number[]. [x, y, z] for the first controller. Zeros on the very first read, or when it is not plugged in or has no motion sensors.

Gamepad.getAxis

Sticks -1 to 1 (up and left are negative), triggers 0 to 1

Gamepad.getAxis(axisName)
Gamepad.getAxis(axisName, index)
Value Type What it is
axisName string The axis name, such as LeftX, LeftY, RightX, RightY, LeftTrigger or RightTrigger.
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: number. The axis value on the first controller, or 0 when it is not plugged in.

Gamepad.getAxisNames

Lists the axis names the axis commands accept: the X and Y of each stick and the two triggers. Trigger aliases such as LT, R2 and ZR work too.

Gamepad.getAxisNames()

Gives back: string[]. The axis names.

Gamepad.getBattery

0 to 100, or -1 when the controller does not say

Gamepad.getBattery()
Gamepad.getBattery(index)
Value Type What it is
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: number. The first controller's battery percent, or -1 when unknown or not plugged in.

Gamepad.getButton

True while the button is held

Gamepad.getButton(buttonName)
Gamepad.getButton(buttonName, index)
Value Type What it is
buttonName string The button name, such as A, B, South, LB, Start or DPadUp.
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: boolean. Whether the button is held down on the first controller; not when it is not plugged in.

Gamepad.getButtonNames

Lists the button names the button commands accept. The Xbox letters and common aliases such as A, LB and Up work too.

Gamepad.getButtonNames()

Gives back: string[]. The button names.

Gamepad.getControllerType

"Xbox", "PS5", "Switch Pro", "Joystick" and so on

Gamepad.getControllerType()
Gamepad.getControllerType(index)
Value Type What it is
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: string. The type of the first controller, or empty text when it is not plugged in.

Gamepad.getCount

How many controllers are connected

Gamepad.getCount()

Gives back: number. The number of controllers plugged in.

Gamepad.getGyro

[x, y, z] in radians per second. Turns the sensors on at the first call

Gamepad.getGyro()
Gamepad.getGyro(index)
Value Type What it is
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: number[]. [x, y, z] for the first controller. Zeros on the very first read, or when it is not plugged in or has no motion sensors.

Gamepad.getHat

"Centered", "Up", "UpRight", "Right", "DownRight", "Down", "DownLeft", "Left" or "UpLeft"

Gamepad.getHat(hatIndex)
Gamepad.getHat(hatIndex, index)
Value Type What it is
hatIndex number Which hat, counting from 0.
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: string. The direction the hat on the first controller is pushed, or Centered when the hat or controller does not exist.

Gamepad.getHatCount

Gets how many hats (the 8-way thumb switches on joysticks) the first controller has.

Gamepad.getHatCount()
Gamepad.getHatCount(index)
Value Type What it is
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: number. The number of hats, or 0 when it is not plugged in.

Gamepad.getName

Gets the name of the first controller. Empty when no controller is plugged in.

Gamepad.getName()
Gamepad.getName(index)
Value Type What it is
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: string. The controller name, or empty text.

Gamepad.getNames

The names of the connected controllers, in index order

Gamepad.getNames()

Gives back: string[]. The controller names, one per connected controller.

Gamepad.getRawAxis

-1 to 1

Gamepad.getRawAxis(axisIndex)
Gamepad.getRawAxis(axisIndex, index)
Value Type What it is
axisIndex number Which raw axis, counting from 0.
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: number. The axis value on the first controller, or 0 when the axis or controller does not exist.

Gamepad.getRawAxisCount

Gets how many raw axes the first controller has. Raw inputs are for joysticks and other controllers that are not recognized gamepads.

Gamepad.getRawAxisCount()
Gamepad.getRawAxisCount(index)
Value Type What it is
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: number. The number of raw axes, or 0 when it is not plugged in.

Gamepad.getRawButton

Checks whether a raw button on the first controller is held down, by number. For joysticks and other controllers without named buttons.

Gamepad.getRawButton(buttonIndex)
Gamepad.getRawButton(buttonIndex, index)
Value Type What it is
buttonIndex number Which raw button, counting from 0.
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: boolean. Whether the button is held; not when the button or controller does not exist.

Gamepad.getRawButtonCount

Gets how many raw buttons the first controller has.

Gamepad.getRawButtonCount()
Gamepad.getRawButtonCount(index)
Value Type What it is
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: number. The number of raw buttons, or 0 when it is not plugged in.

Gamepad.isConnected

Checks whether the first controller is plugged in. Other commands read 0 or nothing from a missing controller instead of failing, so check this when it matters.

Gamepad.isConnected()
Gamepad.isConnected(index)
Value Type What it is
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: boolean. Whether the controller is connected.

Gamepad.isGamepad

False for flight sticks, wheels and unrecognized controllers, which only have raw axes and buttons

Gamepad.isGamepad()
Gamepad.isGamepad(index)
Value Type What it is
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: boolean. Whether the first controller is a recognized gamepad with named sticks and buttons.

Gamepad.rumble

Rumble at a strength of 0 to 1 for the milliseconds given

Gamepad.rumble(strength, durationMs)
Gamepad.rumble(strength, durationMs, index)
Value Type What it is
strength number How strong, from 0 (off) to 1 (full).
durationMs number How long to rumble in milliseconds, up to 60000.
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: boolean. Whether the first controller started rumbling; not when it is not plugged in or cannot rumble.

Gamepad.rumbleMotors

Rumble the heavy (low) and light (high) motors separately, 0 to 1 each. Its own name rather than a Rumble() overload, because rumble(0.5, 0.5, 300) would otherwise mean strength 0.5 for half a millisecond on controller 300

Gamepad.rumbleMotors(lowStrength, highStrength, durationMs)
Gamepad.rumbleMotors(lowStrength, highStrength, durationMs, index)
Value Type What it is
lowStrength number Strength of the heavy (low) motor, from 0 to 1.
highStrength number Strength of the light (high) motor, from 0 to 1.
durationMs number How long to rumble in milliseconds, up to 60000.
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: boolean. Whether the first controller started rumbling; not when it is not plugged in or cannot rumble.

Gamepad.setLED

Set the light bar colour (0 to 255 each) on controllers that have one

Gamepad.setLED(red, green, blue)
Gamepad.setLED(red, green, blue, index)
Value Type What it is
red number Red brightness, 0 to 255.
green number Green brightness, 0 to 255.
blue number Blue brightness, 0 to 255.
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: boolean. Whether the colour was set on the first controller; not when it is not plugged in or has no light.

Gamepad.stopRumble

Stops the first controller rumbling straight away.

Gamepad.stopRumble()
Gamepad.stopRumble(index)
Value Type What it is
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: boolean. Whether it worked; not when the controller is not plugged in or cannot rumble.

Gamepad.waitForButton

Wait for the button to be pressed. True when it was, false on timeout or disconnect. A button already held does not count until it is pressed again

Gamepad.waitForButton(buttonName)
Gamepad.waitForButton(buttonName, timeoutMs)
Gamepad.waitForButton(buttonName, timeoutMs, index)
Value Type What it is
buttonName string The button name, such as A, B, South, LB, Start or DPadUp.
timeoutMs number Optional. The longest to wait in milliseconds. 0 or less waits with no limit.
index number Optional. Which controller, 0 being the first one plugged in.

Gives back: boolean. Whether the button on the first controller was pressed. Waits with no time limit.