// Sweep // by BARRAGAN // This example code is in the public domain. #include Servo gatillo1; Servo gatillo2; Servo gatillo3; Servo cargador; int pos = 0; // variable to store the servo position void setup() { cargador.attach(8); // attaches the servo on pin 9 to the servo object gatillo1.attach(9); // attaches the servo on pin 9 to the servo object gatillo2.attach(10); // attaches the servo on pin 9 to the servo object gatillo3.attach(11); // attaches the servo on pin 9 to the servo object pinMode(4, INPUT); cargador.write(0); // tell servo to go to position in variable 'pos' gatillo1.write(30); // tell servo to go to position in variable 'pos' gatillo2.write(30); // tell servo to go to position in variable 'pos' gatillo3.write(30); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } void disparo1(unsigned long time) { gatillo1.write(130); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position delay(time); } void disparo2(unsigned long time) { gatillo2.write(130); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position delay(time); } void disparo3(unsigned long time) { gatillo3.write(130); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position delay(time); } void recarga() { gatillo1.write(30); // tell servo to go to position in variable 'pos' gatillo2.write(30); // tell servo to go to position in variable 'pos' gatillo3.write(30); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } void giro(int angulo, unsigned long time) { cargador.write(angulo); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position delay(time); } void loop() { if (digitalRead(4)) { disparo1(400); //Tiempo en ms giro(30, 450); //Angulo y tiempo en ms disparo2(400); //Tiempo en ms giro(57,200); //Angulo y tiempo en ms disparo3(400); //Tiempo en ms giro(0, 2000); //Posicion inicial recarga(); } }