Hi!
I'm a newbie and am currently doing my first ever Hexapod ROBOT with 18servo motors controlled using Arduino Mega ADK. I already control 6 servos using 4 pins from arduino (pins 8,9,10,11). However, when i tried controlling the other 6 servos with 4 other pins, something went wrong. it doesnt word at all. It's seems it's my codes fault. Here's my code:
#include <Servo.h>
Servo servoa; // Define a servo
Servo servob;
Servo servoc;
Servo servod;
Servo servoe;
Servo servof;
Servo servog;
Servo servoh;
int i,j,k;
int a=90;
int b=90;
int c=90;
int d=90;
int e=90;
int f=90;
int g=90;
int h=90;
void setup() {
servoa.attach(10); // RightA(4,6)
servob.attach(9); // LeftA(2)
servoc.attach(8); // RightB(4,6)
servod.attach(7); // LeftB(2)
servoe.attach(6); // LeftA(1,3)
servof.attach(5); // RightA(5)
servog.attach(4); // LeftB(1,3)
servoh.attach(3); // RightB(5)
servoa.write(a);
servob.write(b);
servoc.write(c);
servod.write(d);
servoe.write(e);
servof.write(f);
servog.write(g);
servoh.write(h);
}
void loop() { // Loop through motion tests
delay(5000);
for(i=1;i<=30;i++){
a++;
b--;
c++;
d--;
servoa.write(a);
servob.write(b);
servoc.write(c);
servod.write(d);
delay(50);
}
for(i=1;i<=30;i++){
c--;
d++;
servoc.write(c);
servod.write(d);
delay(25);
}
for(i=1;i<=30;i++){
a--;
b++;
e++;
f--;
g++;
h--;
servoa.write(a);
servob.write(b);
servoe.write(e);
servof.write(f);
servog.write(g);
servoh.write(h);
delay(75);
}
for(i=1;i<=30;i++){
g--;
h++;
servog.write(g);
servoh.write(h);
delay(25);
}
for(i=1;i<=30;i++){
e--;
f++;
servoe.write(e);
servof.write(f);
delay(25);
}
}
Can somebody please tell what's wrong with this? Any help would be much appreciated. Thank you!