#include <Servo.h>
// constant variables used to set servo angles, in degrees
const int straight = 90;
const int divergent = 110;
// constant variables holding the ids of the pins we are using
const int buttonpinA = 8;
const int servopinA = 9;
const int buttonpinB = 6;
const int servopinB = 7;
// servo movement step delay, in milliseconds
const int step_delay = 70;
// create a servo object
Servo myservoA;
Servo myservoB;
// global variables to store servo position
int pos = straight; // current
int old_pos = pos; // previous
void loop()
{
int button_state = digitalRead(buttonpinA);
if(button_state == HIGH){
old_pos = pos;
pos = pos == straight ? divergent: straight;
if(old_pos < pos){
for(int i = old_pos + 1; i <= pos; i++){
myservoA.write(i);
delay(step_delay);
}
}else {
for(int i = old_pos - 1; i >= pos; i--){
myservoA.write(i);
delay(step_delay);
}
}
void loop()
int button_state = digitalRead(buttonpinB);
if(button_state == HIGH){
old_pos = pos;
pos = pos == straight ? divergent: straight;
if(old_pos < pos){
for(int i = old_pos + 1; i <= pos; i++){
myservoB.write(i);
delay(step_delay);
}
}else {
for(int i = old_pos - 1; i >= pos; i--){
myservoB.write(i);
delay(step_delay);
}
}
}
}}// end of loop