June 15, 2018

codes

#include <Servo.h>
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;// create servo object to control a servo
// twelve servo objects can be created on most boards

int i = 0;
int pos1 = 0;
int pos2 = 0;
int pos3 = 0;
int pos4 = 0;
int y = 7;
int x = 500;
int lmax = 110;
int lmin = 70;
int f_max = 110;
int f_min = 70;
void setup()
{
myservo1.attach(6); //for foot
myservo2.attach(9);// foot
myservo3.attach(10);// for leg
myservo4.attach(11);// for leg
}

void loop()
{
if (i == 0)
{

delay(x);
for (pos1 = 90; pos1 <= f_max; pos1 += 1)
{ // goes from minimum position to max for foot

myservo2.write(pos1);
myservo1.write(pos1);

delay(y);
}
delay(x);
for (pos3 = 90; pos3 <= lmax; pos3 += 1)
{ // goes from 90 to maximum, for legs

myservo3.write(pos3);
myservo4.write(pos3);

delay(y);
}
delay(x);
i = 1;
}
else
{
for (pos1 = f_min; pos1 <= f_max; pos1 += 1)

{ // goes from minimum angle to maximum for foot
// in steps of 1 degree
myservo1.write(pos1);
myservo2.write(pos1);

delay(y * 2);
}
delay(x);
for (pos3 = lmin; pos3 <= lmax; pos3 += 1)
{ // goes from minimum angle to maximum for legs
// in steps of 1 degree
myservo3.write(pos3);
myservo4.write(pos3);

delay(y * 2);
}
delay(x);

}

for (pos2 = f_max; pos2 >= 90; pos2 -= 1)
{ // goes from minimum angle to 90 for foot
myservo2.write(pos2);
myservo1.write(pos2);
delay(y * 2);
}
for (pos2 = 90; pos2 >= f_min; pos2 -= 1)

{ // goes from 90degree angle to maximum for foot
myservo2.write(pos2);
myservo1.write(pos2);
delay(y * 2);
}
delay(x);

for (pos4 = lmax; pos4 >= lmin; pos4 -= 1)
{ // goes from maximum angle to minimum for legs
myservo4.write(pos4);
myservo3.write(pos4);
delay(y);
}

}