Hello !
Im having trouble with my servo. When my joystick is at "zero" position, my servo still moves a little. I want to know how can i add a deadband to my code so that it wont move. Meaning, when the arduino reads the potentiometer from let's say ... 450 to 600, i went it to servo.write(90) and when it doesnt it should write the normal way. Thanks in advance
#include <Servo.h> // include a library that does all the hard work controlling the servo
Servo servo1; // declare servo #1
int leftJS = 0; // analog input pin for left position
void setup() {
Serial.begin(9600);
pinMode(leftJS, INPUT); // let Arduino know that this is an input
}
void loop() {
leftPOS = analogRead(leftJS); // Left joystick position value (between 0 and 1023)
leftPOS = map(leftPOS, 0,1023,180,0); // Map the values between 180 and 0 degrees
servo1.write(leftPOS); // Make Servo 1 go to angle defined by left joystick position
}
const int centerPOS = 90; // set to the neutral position for your servo
const int deadband = 5;
...
if(abs(leftPOS - centerPOS) < deadband)
{
// position is within the deadband
leftPOS = centerPOS;
}