
buttonsGroup2()
This function works exactly like the buttonsGroup1() function except that it
returns the status of the buttons in Group 2 (Up, Down, Left, Right, L3, R3, Share,
and Options). The command for returning the status of the Group 2 buttons is
ps4.buttons_2.
Notice that because of the way the direction buttons work, it is impossible to hold
all four of them down at the same time.
Hacking the Code
Attach a standard servo and a motor to the PRIZM. Using the example sketch as
reference, write a new sketch to control the servo using these PS4 controls:
• L2 trigger button
• Left joystick
• Touch pad’s xposition
• Roll from the PS4 controller’s gyroscope
Add commands to control the motor using these controls:
• R2 trigger button
• Right joystick
• Touch pad’s yposition
• Pitch from the PS4 controller’s gyroscope
In the void setup() section, include the commands:
Experiment with changing the value of the dead zones from 10 to 0. How does this
affect the servo or motor? Then change the value to 50. Do you notice a difference
in how the servo and motor behave?
Dead Zones
Precisely controlling servos and motors using joysticks can be difficult sometimes
because the joysticks don’t always return to the exact center. This might cause your
servo to not return to its center position or your motor to continue to slowly spin
when the joysticks are released. By setting a dead zone, you identify the size of
an area for the joystick’s x- and y-axis that is considered neutral. When the joystick
returns to this neutral dead zone area, the joystick is considered to be centered.
Setting a higher dead zone value gives you a bigger neutral area but reduces the
sensitivity of the joystick outside the dead zone. On the other hand, a small dead
zone gives you more precise sensitivity but reduces the neutral area of the joystick.
You’ll need to experiment with your controller to find the right balance of joystick
sensitivity and dead zone.
Note: When the binary values of a
button combination are displayed,
the leading zeros are left off.
This is why when the L1 button
is pressed by itself, the function
outputs 1 instead of 00000001.
However, if you hold down the
Triangle button, all eight digits will
appear, and it is easier to see how
each digit represents a different
button. For Group 2, hold down
the Options button to see all eight
digits.
Binary value when only the Options button is pressed.
10 TETRIX Tele-Op Control Module Activity 1