# Using a Gamepad

## Using Gamepads

While our robot is able to do a lot autonomously, more often than not we need, or want, to input commands using a gamepad. There is a wide variety of gamepads that are compatible with the Driver Hub. For this tutorial we will be focusing on a generic PS4 controller, such as the, [REV USB PS4 Compatible Gamepad](https://www.revrobotics.com/rev-31-2983/), or an [Etpark Wired Controller.](https://www.revrobotics.com/rev-39-1865/)

{% hint style="info" %}
To initialize the gamepad that will act as User 1 (gamepad1, in code) press the options button and the Cross/A button on the gamepad at the same time. To initialize User 2 ( gamepad2, in code) press the options button and the Circle/B button at the same time.
{% endhint %}

<figure><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUOOiQ4S2QcMWmVoSmeQ8%2Fuploads%2F60sKhYU1bQRfklE3Obne%2Fimage.png?alt=media&#x26;token=cd077107-f161-46ee-9aa7-e5576c0759a4" alt=""><figcaption></figcaption></figure>

All buttons on a gamepad can be programmed to a specific task or behavior. Let's take a look at the breakdown of each button, their associated block name, and the type of data they output:&#x20;

<figure><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUOOiQ4S2QcMWmVoSmeQ8%2Fuploads%2FN9vuNwWxgNYUMLBCfb51%2Fimage.png?alt=media&#x26;token=cf9f4fb7-9e26-4491-b9b5-6499d88aab9c" alt=""><figcaption></figcaption></figure>

<table><thead><tr><th width="157" align="center">PS4 Controllers</th><th width="142" align="center">Generic USB Gamepad</th><th width="257" align="center">Blocks</th><th align="center">Data Type</th></tr></thead><tbody><tr><td align="center">Cross</td><td align="center">a</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-MefyGMd_cjtIMfaGFye%2Fgampad_a.svg?alt=media&#x26;token=dd90bd44-5a3a-43bb-82d6-990ccb011666" alt="" data-size="original"> </td><td align="center">Boolean</td></tr><tr><td align="center">Circle</td><td align="center">b</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-MefyIl-Ll13ocSPLPBb%2Fgampad_b.svg?alt=media&#x26;token=6fa37c13-a24c-4a04-8a98-31a398bd259e" alt="" data-size="original"> </td><td align="center">Boolean</td></tr><tr><td align="center">Triangle</td><td align="center">y</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-MefyLTC5XT0ZCUcL4qa%2Fgampad_y.svg?alt=media&#x26;token=b1e666ba-1574-4609-8599-80e594a0f988" alt="" data-size="original"> </td><td align="center">Boolean</td></tr><tr><td align="center">Square</td><td align="center">x</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-MefyNihIOjS-Ex05c3V%2Fgampad_x.svg?alt=media&#x26;token=b0a8b9de-9ac3-4b76-9657-0e8037d7a49c" alt="" data-size="original"> </td><td align="center">Boolean</td></tr><tr><td align="center">Dpad Up </td><td align="center">Dpad Up</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-MefyQc43fGBd8YPQ1KH%2Fgampad_DpadUp.svg?alt=media&#x26;token=64b363fd-fb6d-4c76-9026-bb9b2e7f02cc" alt="" data-size="original"> </td><td align="center">Boolean</td></tr><tr><td align="center">Dpad Down</td><td align="center">Dpad Down</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-MefyWzBxrbhm_nxZdwK%2Fgampad_DpadDown.svg?alt=media&#x26;token=deaf0174-06fd-4ffa-9f16-cbf05d2357a5" alt="" data-size="original"> </td><td align="center">Boolean</td></tr><tr><td align="center">Dpad Left</td><td align="center">Dpad Left</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-MefyZrTvZ4--3FR-LtP%2Fgampad_DpadLeft.svg?alt=media&#x26;token=fc6053b7-1b9f-404a-917c-e09665a0e3f7" alt="" data-size="original"> </td><td align="center">Boolean</td></tr><tr><td align="center">Dpad Right</td><td align="center">Dpad Right</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-MefycRzLKZCh8Nyihuf%2Fgampad_DpadRight.svg?alt=media&#x26;token=56fddd18-dae8-4923-896b-c8ec47142200" alt="" data-size="original"> </td><td align="center">Boolean</td></tr><tr><td align="center">Left Bumper</td><td align="center">Left Bumper</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-MefvsReeMM-BoSDwSo9%2Fgampad_LefBumper.svg?alt=media&#x26;token=81174557-1b7e-4fc5-bd6e-096401928904" alt="" data-size="original"> </td><td align="center">Boolean</td></tr><tr><td align="center">Right Bumper</td><td align="center">Right Bumper</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-MefyhTGT065OSFPQMsO%2Fgampad_RightBumper.svg?alt=media&#x26;token=5d912eb0-bf4c-4f91-bd7b-918ca3e2653c" alt="" data-size="original"> </td><td align="center">Boolean</td></tr><tr><td align="center">Left Trigger</td><td align="center">Left Trigger</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-Meg1ixhp5UYWLTIwpfA%2Fgampad_LeftTrigger.svg?alt=media&#x26;token=a914fdbd-2fb1-405a-9864-2917600753ea" alt="" data-size="original"> </td><td align="center">Float</td></tr><tr><td align="center">Right Trigger</td><td align="center">Right Trigger</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-Meg1l3U6mcavar6qAT0%2Fgampad_RightTrigger.svg?alt=media&#x26;token=e6acdacf-3d2a-45b7-bda0-dcd17a9d8bae" alt="" data-size="original"> </td><td align="center">Float</td></tr><tr><td align="center">PS</td><td align="center">Home</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-Meg23NRA8GyJEd6wi5t%2Fgampad_PS.svg?alt=media&#x26;token=37580382-0dd9-486e-9772-cb366291862f" alt="" data-size="original"> </td><td align="center">Boolean</td></tr><tr><td align="center">Options</td><td align="center">Start/Options</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-Meg25mUFbikYvJ0CP2o%2Fgampad_Start.svg?alt=media&#x26;token=3e8f2326-0fea-417d-9263-4cd919930cf2" alt="" data-size="original"> </td><td align="center">Boolean</td></tr><tr><td align="center">Share</td><td align="center">Back/Share</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-Meg289jpsjclF39NFy6%2Fgampad_Back.svg?alt=media&#x26;token=a3227121-7317-4907-ae6b-b706b40492d4" alt="" data-size="original"> </td><td align="center">Boolean</td></tr><tr><td align="center">Left Stick Button</td><td align="center">Left Stick Button</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-MefymdCUyynn8QoQhb5%2Fgampad_LeftStickButton.svg?alt=media&#x26;token=38dc7618-56a6-4568-9cd8-b5d6d6db4f8d" alt="" data-size="original"></td><td align="center">Boolean</td></tr><tr><td align="center">Left Stick X Axis</td><td align="center">Left Stick X Axis</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-Meg2Bkc5e_G0-UfhDL7%2Fgampad_LeftStickX.svg?alt=media&#x26;token=75127398-a2a9-407a-82b6-39f1db9479b3" alt="" data-size="original"> </td><td align="center">Float</td></tr><tr><td align="center">Left Stick Y Axis</td><td align="center">Left Stick Y Axis</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-Meg2EWU1Uo-OOYRTZdx%2Fgampad_LeftStickY.svg?alt=media&#x26;token=0223c867-f1b0-4d63-9a0c-b62f59bee112" alt="" data-size="original"> </td><td align="center">Float</td></tr><tr><td align="center">Right Stick Button</td><td align="center">Right Stick Button</td><td align="center"> <img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-Mefypw4O9JtYoO9CQQj%2Fgampad_RightStickButton.svg?alt=media&#x26;token=570245c6-3d49-4c76-ac45-9f9bbf8c578d" alt="" data-size="original"> </td><td align="center">Boolean</td></tr><tr><td align="center">Right Stick X Axis</td><td align="center">Right Stick X Axis</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-Meg2IxQy9Nnb5ojouxt%2Fgampad_RighStickX.svg?alt=media&#x26;token=fb93265e-8985-4caf-a8c3-e23f54ef256a" alt="" data-size="original"> </td><td align="center">Float</td></tr><tr><td align="center">Right Stick Y Axis</td><td align="center">Right Stick Y Axis</td><td align="center"><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MefjIYccgNxbJIm89ND%2F-Meg2Lw3rWVWYEzLC8sq%2Fgampad_RighStickY.svg?alt=media&#x26;token=f0ec5796-c8fc-4f73-8ae3-09ebda0a95f7" alt="" data-size="original"> </td><td align="center">Float</td></tr></tbody></table>

## Boolean vs Float Data Types

The gamepad outputs two types of data back to the Control Hub to be used within the program:

### Boolean&#x20;

Boolean data has two possible values: **True and False**. These two values can also be represented by **On and Off** or **1 and 0**.&#x20;

The buttons, bumpers, and triggers on the gamepad provide boolean data to our robot! For example, a button that is not pressed will return a value of False (or 0) and a button that is pressed will return the value True (or 1).&#x20;

### Float

Float data is a number that can include decimal places and positive or negative values.&#x20;

On the gamepad, the float data returned will be between 1 and -1 for the joystick's position on each axis. Some examples of possible values are 0.44, 0, -0.29, or -1.&#x20;
