how do i write a programme for arduino to control more than one servo?
thanks that works great!!!
ye I've used both sweep and knob for one servo so I've gotten that far!!!!How do you declare two servos?
// 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 potpintwo = 1;
int val; // variable to read the value from the analog pin
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)
valtwo = analogRead(potpintwo);
valtwo = map(valtwo, 0, 1023, 0, 179);
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(15); // waits for the servo to get there
Where are you so far? Have you gotten one servo to move? Did you use the "knob" or "sweep" example?
As an overview, you will need to declare 2 servos, attach them and also declare 2 variables that you can use to store the position of each servo. From there, it will be identical to either of the examples shown in the IDE, except you will have a 2 sets of servo commands and 2 sets of variables containing the positions.