I am having a problem with my circuit, I have the following code (pdf attached) that runs a blinking LED and servo off one potentiometer. With the addition of an LED for the potentiometer the servo becomes jittery, not as responsive. Can anyone tell me why it suddenly becomes jittery and how it can be fixed?
ard.pdf (16.8 KB)
Could it be anything to do with the up to 398ms of delays?
Nothing happens during a delay(). Whether that nothing extends to servo pulse sending, or not, I'm not sure. You could look at the blink without delay example to see how to make things happen on a fixed schedule, without using delay().
I have the following code (pdf attached)
There is the # in the tool bar when you are making a post for including your code. How are you powering your servo? Servos do not power well via USB.
key in action...
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int ledPin = 13;
myservo.attach(9); // attaches the servo on pin 9 to the servo object
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(40); // waits for the servo to get there
digitalWrite(ledPin, HIGH); // turn the ledPin on
delay(val); // stop the program for some time
digitalWrite(ledPin, LOW); // turn the ledPin off