It's time to get back in control... with the gamepad blocks.
The Gamepad (Trigger) 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 (Triggers) block returns a value based on the position of either the left or right gamepad trigger. This value can be assigned to a Single Motor block for example to rotate the motor based on the extent to which the trigger is pressed.
The default value (not pressed) of a trigger is 0. The values can range from 0 to 1, depending on how much the trigger is pressed. Because of the base range of the values, the values should be multiplied by 100 using a numerical operator block in order to extend the range to 0 to 100, which allows for better control of motor blocks, whose range is -100 to 100.
To apply the gamepad (triggers) 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 (Triggers) block to the first slot of the numerical operator.
- Use the right drop-down menu to assign the desired trigger. Use the left drop-down menu to select the gamepad being used, if necessary.
- Using the numerical operator and a numerical data block, multiply the value of the gamepad (triggers) block by 100.
When this program executes, pulling the left trigger controls the left motor, and pulling the right trigger controls the right motor.
Select the desired gamepad.
Select the desired trigger (left/right).