I'm using a PS3 controller to control a continuous servo array. I'm using the map function to write the servo position. The relevant part of my code is
servo1.writeMicroseconds(map(PS3.getAnalogHat(RightHatY), 0, 255, 1300, 1700));
My problem is that the joysticks don't usually reset back exactly to the midpoint which makes the servos slowly rotate when I want them to stay still. I want to ignore the input from 115 to 140 from the ps3 controller.
How would I go about doing this?
Option One
The following is the map function's definition which includes the ignoration of input between the values of 115 and 140. You can change these to your personal preference.
long map(long x, long in_min, long in_max, long out_min, long out_max) {
if(x > 115 && x < 140)
return 1500;
else return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
Option Two
Another option is to include a selection statement to not map anything in the given range in the main function (loop) like the following:
long analogPS3Value = PS3.getAnalogHat(RightHatY);
if(analogPS3Value > 115 && analogPS3Value < 140)
servo1.writeMicroseconds(1500);
else
servo1.writeMicroseconds(map(analogPS3Value, 0, 255, 1300, 1700));
Practically, it keeps the servo steady at halfway distance between 1300 and 1700 (which is 1500) when the read value is between 115 and 140 for either of the above options you want to implement.