I'm trying to make a robot arm basically show off by making it sweep in different directions. I promise I have everything hooked up right, I still can't get this to work for some reason though. Here's my code:
#include <Servo.h>
// "//" dictates a single line comment. Anything following a double slash doesn't affect the operation of the robot arm
int pos1; //the variable that "stores" the position of the servo
int pos2;
int pos3;
int pos4;
int pos5;
int pos6;
int pos7;
//Servo related pre-loop setup
Servo base;
Servo shoulder1;
Servo shoulder2;
Servo elbow;
Servo wristy;
Servo wristx;
Servo claw;
void setup ()
{
//Servo related void setup
base.attach (2);
shoulder1.attach (3);
shoulder2.attach (4);
elbow.attach (5);
wristy.attach (6);
wristx.attach (7);
claw.attach (8);
}
void loop ()
{
for (pos1 = 0; pos1 < 90; pos1 += 1) //tells the servo to go from 0 to 180 degress in steps of 1 degree
{
shoulder1.write (pos1); //tells the servo to go to its postition
delay(45); //gives the servo time to get there
}
for (pos1 = 90; pos1 >= 1; pos1 -= 1)
{
shoulder1.write (pos1);
delay(45);
}
for (pos2 = 90; pos2 < 0; pos2 += 1)
{
shoulder2.write (pos2);
delay(45);
}
for (pos2 = 0; pos2 >= 1; pos2 -= 1)
{
shoulder2.write (pos2);
delay(45);
}
for (pos3 = 100; pos3 < 0; pos3 += 1)
{
elbow.write (pos3);
delay(45);
}
for (pos3 = 0; pos3 >= 1; pos3 -= 1)
{
elbow.write (pos3);
delay(45);
}
for (pos4 = 100; pos4 < 0; pos4 += 1)
{
wristy.write (pos4);
delay(45);
}
for (pos4 = 0; pos4 >= 1; pos4 -= 1)
{
wristy.write (pos4);
delay(45);
}
for (pos5 = 60; pos5 < 120; pos5 += 1)
{
base.write (pos5);
delay(100);
}
for (pos5 = 120; pos5 >= 1; pos5 -= 1)
{
base.write (pos5);
delay(100);
}
for (pos6 = 70; pos6 < 110; pos6 += 1)
{
claw.write (pos6);
delay(45);
}
for (pos6 = 110; pos6 >= 1; pos6 -= 1)
{
claw.write (pos6);
delay(45);
}
}
All that happens when I load this onto my arduino (Due) is the elbow goes up and down once, then the base turns in one direction, starts turning in the other direction and then doesn't stop.
Thanks in advance