#include <Servo.h>
#define PIN_SERVO 9
#define PIN_STOP 2
#define PIN_CCW 3
#define PIN_CW 4
#define PIN_RED 11
#define PIN_BLUE 12
#define PIN_GREEN 13
enum Shaft {
CW = 270, CCW = 70, STOP = 110
};
Servo servo;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(PIN_STOP, INPUT_PULLUP);
pinMode(PIN_CCW, INPUT_PULLUP);
pinMode(PIN_CW, INPUT_PULLUP);
pinMode(PIN_RED, OUTPUT);
pinMode(PIN_GREEN, OUTPUT);
pinMode(PIN_BLUE, OUTPUT);
servo.attach(PIN_SERVO);
servo.write(90);
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(PIN_CW) == LOW) {
servoStart(Shaft::CW);
digitalWrite(PIN_GREEN, HIGH);
} else if (digitalRead(PIN_CCW) == LOW) {
servoStart(Shaft::CCW);
digitalWrite(PIN_BLUE, HIGH);
} else if (digitalRead(PIN_STOP) == LOW) {
servoStart(Shaft::STOP);
digitalWrite(PIN_RED, HIGH);
} else if (digitalRead(PIN_CW) == HIGH) {
digitalWrite(PIN_GREEN, LOW);
} else if (digitalRead(PIN_CCW) == HIGH) {
digitalWrite(PIN_BLUE, LOW);
} else if (digitalRead(PIN_STOP) == HIGH) {
digitalWrite(PIN_RED, LOW);
}
}
void servoStart(Shaft theta) {
servo.write(theta);
// switch (theta) {
// case Shaft::CW:
// servo.write(theta);
// break;
// case Shaft::CCW:
// servo.write(theta);
// break;
// case Shaft::STOP:
// servo.write(theta);
// break;
// }
}