It's time to get back in control... with the gamepad blocks.
The Gamepad (Sticks) block allows you to control the motors and servos of your robot with the gamepad. This block enables this type of function by providing the motor or servo blocks with values from the actual input from the pad. All blocks from the Gamepad section of the Block Library must be placed inside a Repeat While True loop so that the commands repeat indefinitely.
The Gamepad (sticks) block returns a value based on the x-axis (left/right) or y-axis (up/down) position of either the left or right gamepad joystick. This value can be assigned to a Single Motor block for example to rotate the motor based on in which direction and the extent to which the stick is pushed.
The default value (not pushed in any direction) of a joystick is 0. The values can range from -1 to 1, depending on how far the stick is pushed in each direction. Because of the base range of the values, the values must be multiplied by 100 using a numerical operator block in order to extend the range to -100 to 100, which is the base range of the motor blocks.
To apply the gamepad (sticks) block to a program:
- Add a motor or servo block into a Repeat While True loop.
- Add a Numerical Operator block to one of the parameters (or the single parameter) of the motor block.
- Add the Gamepad (Sticks) block to the first slot of the numerical operator.
- Using the numerical operator, multiply the value of the gamepad (sticks) block by 100.
- Use the central and right drop-down menus to select the assignment for one of the sticks in either the x or y direction, respectively. Use the left drop-down menu to select the gamepad being used, if necessary.
When this program executes, the up/down movement of the left stick controls the left motor, and the up/down movement of the right stick controls the right motor.
Select the desired gamepad.
Select the desired stick (left/right).
|Axis||Select the desired axis (x/y).|