#include "Servo.h"
const int N = 2;
Servo servo [N];
const byte PinServo [N] = { A0, A1 };
const byte PinBut [N] = { 10, 4 };
int angNorm [N] = { 40, 130 };
int angRev [N] = { 100, 90 };
bool normal [N] = { true, false};
void setup() {
Serial.begin(115200);
Serial.println("button-servo");
for (int n = 0; n < N; n++) {
pinMode (PinBut [n], INPUT_PULLUP);
servo [n].attach (PinServo [n]);
}
}
void loop() {
for (int n = 0; n < N; n++) {
if (LOW == digitalRead(PinBut [n])) { // button pressed
normal [n] = ! normal [n];
}
if (normal [n])
servo [n].write (angNorm [n]);
else
servo [n].write (angRev [n]);
}
delay (500); // 500 msec delay
}