I have a servo ( 4 turns type ) that jitters at position and I cant seem to get it to stop jittering , I want to DETACH the servo when it gets to position to stop the jitter , I tried using myservo.detach() on pin 9 ( so it should be myservo.detach(9) right ? ) If I put the 9 in there it will not compile ?
how should this code be written ? I looked up some other discussions about this but could not get it to work.
//Nanometer tech regulator 0-25 psi rev F
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
double val; // variable to read the value from the analog pin
double mapf(double val, double in_min, double in_max, double out_min, double out_max) {
return (val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
}
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = mapf((double)val, 0.0, 1023.0, 1000.0, 2080.0);// scale it to use it with the servo (value between 0 and 180)
myservo.writeMicroseconds(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
int sensorValue2 = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage2 = sensorValue2 * (5.0 / 1023.0);
Serial.println(voltage2);
Serial.println("Volts");
Serial.println(val);
delay(450);
}