#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
int servoangle = 90;
int posicion = 0;
int buttonpin1 = 11;
int buttonpin2 = 6;
//boton
//Times
unsigned long timezero;
unsigned long vel = 4; //velocidad
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
servo1.attach(10);
servo2.attach(9);
servo3.attach(5);
servo1.write(servoangle);
servo2.write(servoangle);
servo3.write(servoangle);
pinMode(buttonpin1, INPUT);
pinMode(buttonpin2, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long time = millis();
if( time - timezero >= vel) {
timezero = time;
bool button1 = false;
if( digitalRead( 11) == LOW) {
button1 = true;
}
bool button2 = false;
if( digitalRead( 6) == LOW) {
button2 = true;
}
if( posicion == 0 and button2)
posicion = 1;
else if( posicion == 0 and button1)
posicion = -1;
else if( posicion > 0 and button1)
posicion = -1;
else if( posicion < 0 and button2)
posicion = +1;
servoangle += posicion;
if( servoangle <= 0)
{
servoangle = 0;
posicion = 0;
}
else if( servoangle >= 180)
{
servoangle = 180;
posicion = 0;
}
servo1.write( servoangle);
servo2.write( servoangle);
servo3.write( servoangle);
}
}