Hello all,
I am working on a project with 4 servos, and 4 potentiometers.
I will include my coding momentarily. Here is my dilemma.
As the title states: "4 servos all turning at once with one potentiometer...This is NOT the way the project is to work."
The project is to turn each servo unit with its own potentiometer (dial style). I have compiled my coding and it all comes out ok, I then upload it with no issue.
I then attempt to turn the pot and all 4 turn, and if I may add, with quite a bit of jitterness.
Can you please take a moment, look at the code and advise where you think the problem is.
This code was the KNOB example from the Arduino UNO example library. I removed the name of the person as I have continued to add to the program.
You will see the things I have added as I have notated them.
Thanks in advance,
Anna
Now the code:
#include <Servo.h>
Servo myservo0; // create servo object to control a servo
Servo myservo1; // i added
Servo myservo2; // i added
Servo myservo3; // i added
int potpin0 = 0; // analog pin used to connect the potentiometer (i added the zero to the potpin before the equal sign)
int val0; // variable to read the value from the analog pin
int potpin1 = 1; // i added
int val1; // i added
int potpin2 = 2; // i added
int val2; // i added
int potpin3 = 3; // i added
int val3; // i added
void setup()
{
myservo0.attach(3); // attaches the servo on pin 3 to the servo object --- I changed it to 3 from previously 9 - Anna
myservo1.attach(5); // i added
myservo2.attach(6); // i added
myservo3.attach(9); // i added
}
void loop()
{
val0 = analogRead(potpin0); // reads the value of the potentiometer (value between 0 and 1023)
val0 = map(val0, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo0.write(val0); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
val1 = analogRead(potpin1); // i added
val1 = map(val1, 0, 1023, 0, 179); // i added
myservo1.write(val1); // i added
delay(15);
val2 = analogRead(potpin2); // i added
val2 = map(val2, 0, 1023, 0, 179); // i added
myservo2.write(val2); // i added
delay(15);
val3 = analogRead(potpin3); // i added
val3 = map(val3, 0, 1023, 0, 179); // i added
myservo3.write(val3); // i added
delay(15);
}
Message was edited by: Annasta Brandon My project question was answered, now on to part 2... http://www.element14.com/community/thread/24030