I am trying to rebuild a hexa pod I have from a different comtroler (Stamp) and have a basic servo code, which works fine for one servo.
Now here comes the problem if I add a second servo and duplicare the basic servo code (with a second servo object).
whin I run the attached code the 1st servo only steps 1 incriment (it does not go through the entire range of motion) and then the 2nd servo goes through an entire range of movement waits 2 sec and then runs again. servo 1 only steps once rhroughout the run of the program. As far as I can figure it is falling through to the second "for" condition.
How do I fix this, I want the 1st servo to go through its full range then 2nd servo goes through the full range of movement and then back to 1st servo etc...
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
// Pin 9 = data servo 1
// Pin 10 = data servo 2
#include <Servo.h>
Servo myservo; // create servo object to control a servo0
Servo myserv1; // create servo object to control a servo1
int pos = 0; // variable to store the servo position
init pos1 = 0;
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.attach(10);
}
void loop()
{
for(pos = 0; pos < 145; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay(50);
for(pos = 145; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
// set the LED on
delay(50); // wait
for(pos = 0; pos < 145; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myserv1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay(50);
for(pos = 145; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myserv1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay(50); // wait
}
UncleMike