Refloto el post.
He llegado a esto, que se asemeja mucho a lo que quiero.
#include <Servo.h>
//Pines que soportan PWM:
Servo servoFront; // Define Servo de moviento frontal (de 90 a 0)
Servo servoLateral;
//Pin usado como entrada para reconocer el boton:
int pinButton = 7;
//Variable para guardar el estado del boton:
int buttonValue;
//Variable para elegir color.
int count = 0;
//Variables auxiliares:
int button_old = 0;
void setup() {
servoFront.attach(10); // Servo de movimento frontal en pin 10
servoLateral.attach(11); // Servo de movimiento lateral en pin 9
//Inicializo pin de entrada:
pinMode(pinButton,INPUT);
}
void loop()
{
//Se guarda el estado del pin en la variable
buttonValue = digitalRead(pinButton);
if(button_old == 0 && buttonValue == 1)
{
count++; //Se le suma uno al valor de count
button_old = 1; //Se cambia el valor auxiliar para reconocer boton presionado
}
if(button_old == 1 && buttonValue == 0)
button_old = 0; //Se cambia valor auxiliar para reconocer boton no presionado
if(count > 7)
count = 0;
}
void mov(int movNumber){
switch(movNumber){
case 0:
servoFront.write(90);
servoLateral.write(90);
delay(1500);
servoFront.write(90);
servoLateral.write(45);
delay(1000);
servoFront.write(90);
servoLateral.write(135);
break;
case 1:
servoFront.write(90);
servoLateral.write(90);
delay(1500);
servoFront.write(45);
servoLateral.write(90);
delay(500);
servoFront.write(90);
servoLateral.write(90);
break;
case 2:
servoFront.write(90);
servoLateral.write(135);
break;
case 3:
servoFront.write(90);
servoLateral.write(90);
break;
case 4:
servoFront.write(45);
servoLateral.write(90);
break;
case 5:
servoFront.write(90);
servoLateral.write(90);
break;
case 6:
servoFront.write(90);
servoLateral.write(135);
break;
return;
}
}
El problema que el pulsador solo accionar un movimiento cada vez. Es decir, pulso una vez y mueve servoFront y servoLateral una vez, en vez de hacer todo el recorrido de case 0, cuando vuelvo a pulsar, hace el segundo movimiento de cada servo incluido en case 0.
¿Alguna sugerencia?