#include "Servo.h"
struct Ctlr {
const byte PinServo;
const byte PinButNorm;
const byte PinButRev;
int angNorm;
int angRev;
Servo servo;
};
const int N = 5;
Ctlr ctlr [N] = {
// Srv Norm Rev norm rev
{ A0, 13, 4, 40, 120 },
{ A1, 12, 5, 45, 140 },
{ A2, 11, 6, 120, 10 },
{ A3, 10, 7, 90, 60 },
{ A4, 9, 8, 20, 170 },
};
void setup() {
Serial.begin(115200);
Serial.println("button-servo");
for (int n = 0; n < N; n++) {
pinMode (ctlr [n].PinButNorm, INPUT_PULLUP);
pinMode (ctlr [n].PinButRev , INPUT_PULLUP);
ctlr [n].servo.attach (ctlr [n].PinServo);
ctlr [n].servo.write (ctlr [n].angNorm);
}
}
void loop() {
for (int n = 0; n < N; n++) {
if (LOW == digitalRead(ctlr [n].PinButNorm)) {
ctlr [n].servo.write (ctlr [n].angNorm);
Serial.println("up");
}
if (LOW == digitalRead(ctlr [n].PinButRev)) {
ctlr [n].servo.write (ctlr [n].angRev);
Serial.println("dn");
}
}
}