Paso 2: cargar el código de arduino
#include < Servo.h >int incomingByte = 0;
Servo myservo;
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
Servo myservo6;
Servo myservo7;
pos doble = 90;
pos1 doble = 90;
doble pos2 = 90;
pos3 doble = 90;
pos4 doble = 90;
pos5 doble = 90;
pos6 doble = 90;
pos7 doble = 90;
int aut = 0;
aut1 int = 0;
aut2 int = 0;
aut3 int = 0;
void setup() {}
pinMode (13, salida);
Serial.Begin(9600);
myservo.Attach(12);
myservo1.Attach(9);
myservo2.Attach(8);
myservo3.Attach(7);
myservo4.Attach(6);
myservo5.Attach(5);
myservo6.Attach(4);
myservo7.Attach(3);
myservo.Write(POS);
myservo1.Write(Pos1);
myservo2.Write(POS2);
myservo3.Write(pos3);
myservo4.Write(pos4);
myservo5.Write(pos5);
myservo6.Write(pos6);
myservo7.Write(pos7);
}
void loop() {}
incomingByte = Serial.read();
Si (incomingByte == 66 & & pos > 10) {}
myservo.Write (pos-= 0.2);
}
Si (incomingByte == 65 & & pos < 180) {}
myservo.Write (pos += 0.2);
}
Si (incomingByte == 68 & & pos1 < 180) {}
myservo1.Write (pos1 += 0.2);
}
Si (incomingByte == 67 & & pos1 > 10) {}
myservo1.Write (pos1-= 0.2);
}
Si (incomingByte == 97) {}
digitalWrite(13,HIGH);}
Si (incomingByte == 98) {}
digitalWrite(13,LOW);}
Si (incomingByte == 82) {}
AUT = 1;}
while(AUT == 1) {}
incomingByte = Serial.read();
para (pos1 = 10; pos1 < 180; pos1 += 0.2)
{
incomingByte = Serial.read();
myservo1.Write(Pos1);
Si (incomingByte == 83) {}
AUT = 0;
}
Delay(15);
}
para (pos1 = 180; pos1 > = 10; pos1-= 0.2)
{
incomingByte = Serial.read();
myservo1.Write(Pos1);
Si (incomingByte == 83) {}
AUT = 0;
}
Delay(15);
}
}
Si (incomingByte == 70 & & pos2 > 10) {}
myservo2.Write (pos2-= 0.2);
}
Si (incomingByte == 69 & & pos2 < 180) {}
myservo2.Write (pos2 += 0.2);
}
Si (incomingByte == 72 & & pos3 < 180) {}
myservo3.Write (pos3 += 0.2);
}
Si (incomingByte == 71 & & pos3 > 10) {}
myservo3.Write (pos3-= 0.2);
}
Si (incomingByte == 84) {}
aut1 = 1;}
while(aut1 == 1) {}
incomingByte = Serial.read();
para (pos3 = 10; pos3 < 180; pos3 += 0.2)
{
incomingByte = Serial.read();
myservo3.Write(pos3);
Si (incomingByte == 85) {}
aut1 = 0;
}
Delay(15);
}
para (pos3 = 180; pos3 > = 10; pos3-= 0.2)
{
incomingByte = Serial.read();
myservo3.Write(pos3);
Si (incomingByte == 85) {}
aut1 = 0;
}
Delay(15);
}
}
Si (incomingByte == 74 & & pos4 > 10) {}
myservo4.Write (pos4-= 0.2);
}
Si (incomingByte == 73 & & pos4 < 180) {}
myservo4.Write (pos4 += 0.2);
}
Si (incomingByte == 76 & & pos5 < 180) {}
myservo5.Write (pos5 += 0.2);
}
Si (incomingByte == 75 & & pos5 > 10) {}
myservo5.Write (pos5-= 0.2);
}
Si (incomingByte == 86) {}
aut2 = 1;}
while(aut2 == 1) {}
incomingByte = Serial.read();
para (pos5 = 10; pos5 < 180; pos5 += 0.2)
{
incomingByte = Serial.read();
myservo5.Write(pos5);
Si (incomingByte == 87) {}
aut2 = 0;
}
Delay(15);
}
para (pos5 = 180; pos5 > = 10; pos5-= 0.2)
{
incomingByte = Serial.read();
myservo5.Write(pos5);
Si (incomingByte == 87) {}
aut2 = 0;
}
Delay(15);
}
}
Si (incomingByte == 78 & & pos6 > 10) {}
myservo6.Write (pos6-= 0.2);
}
Si (incomingByte == 77 & & pos6 < 180) {}
myservo6.Write (pos6 += 0.2);
}
Si (incomingByte == 80 & & pos7 < 180) {}
myservo7.Write (pos7 += 0.2);
}
Si (incomingByte == 79 & & pos7 > 10) {}
myservo7.Write (pos7-= 0.2);
}
Si (incomingByte == 88) {}
aut3 = 1;}
while(aut3 == 1) {}
incomingByte = Serial.read();
para (pos7 = 10; pos7 < 180; pos7 += 0.2)
{
incomingByte = Serial.read();
myservo7.Write(pos7);
Si (incomingByte == 89) {}
aut3 = 0;
}
Delay(15);
}
para (pos7 = 180; pos7 > = 10; pos7-= 0.2)
{
incomingByte = Serial.read();
myservo7.Write(pos7);
Si (incomingByte == 89) {}
aut3 = 0;
}
Delay(15);
}
}
Si (incomingByte == 99) {}
aut3 = 1;}
while(aut3 == 1) {}
incomingByte = Serial.read();
para (pos7 = 10; pos7 < 180; pos7 += 0.2)
{
incomingByte = Serial.read();
myservo1.Write(pos7);
myservo3.Write(pos7);
myservo5.Write(pos7);
myservo7.Write(pos7);
Si (incomingByte == 100) {}
aut3 = 0;
}
Delay(15);
}
para (pos7 = 180; pos7 > = 10; pos7-= 0.2)
{
incomingByte = Serial.read();
myservo1.Write(pos7);
myservo3.Write(pos7);
myservo5.Write(pos7);
myservo7.Write(pos7);
Si (incomingByte == 100) {}
aut3 = 0;
}
Delay(15);
}
}
}