I am trying to control an Arduino uno board using DualShock 4 (PS4). I find it difficult to program joysticks; PS4.getAnalogHat(LeftHatY)I want to control the engine with a joystick; I want the engine to move forward when I push up ( ++i), back when I press ( --i), and without speed when I do not move the joystick. I can move the engine in one direction, and the speed increases, but I can not get the other direction to work. I do not see the connection between the values of the joystick (PS4.getAnalogHat(LeftHatY) > 137 || PS4.getAnalogHat(LeftHatY) < 117)and the values of the engine ( 0- 255).
I use a USB screen and a motor shield.
I need help defining the first if statement.
Here is the code that I still have:
if (PS4.connected())
{
if (PS4.getAnalogHat(LeftHatY) > 137)
{
M3->setSpeed(255));
PS4.setLed(Green);
PS4.setLedFlash(100 ,100);
}
}
I want to increase the M3 value while increasing the joystick angle:
for (int i=0; i<=255; ++i)
M3->setSpeed(i);