#include <Servo.h>
// constant variables used to set servo angles, in degrees
const int straight = 25;
const int divergent = 150;
// constant variables holding the ids of the pins we are using
const int TMainFront = 0;
const int TMainSide = 1;
const int SPinMainFront = 3;
const int SPinMainSide = 5;
// servo movement step delay, in milliseconds
const int step_delay = 70;
// create a servo object
Servo ser1;
Servo ser2;
// global variables to store servo position
int pos = straight; // current
int old_pos = pos; // previous
void setup()
{
// set the mode for the digital pins in use
pinMode(TMainFront, INPUT);
pinMode(TMainSide, INPUT);
// setup the servo
ser1.attach(SPinMainFront); // attach to the servo on pin 3
ser1.write(0);
ser2.attach(SPinMainSide); // attach to the servo on pin 5
ser2.write(0);
}
void loop()
{
// start each iteration of the loop by reading the button
// if the switch is flicked (reads HIGH), move the servo
// if not the switch is flicked, leave where it was
if (TMainFront == HIGH) {
ser1.write(divergent);
} else {
ser1.write(straight);}
delay(55);
if (TMainSide == HIGH) {
ser2.write(straight);
} else {
ser2.write(divergent);}
delay(900);
}