#include <Servo.h>
Servo myServo;
int servoPin = 9;
int stopPin = 4;
int cwPin = 3;
int ccwPin = 5;
int sc [] = {180,110,0};
String scText[] = {"CCW","STOP","CW"};
int statusText;
int CWBS,CCWBS,SBS;
void setup() {
Serial.begin(9600);
pinMode(stopPin, INPUT_PULLUP);
pinMode(ccwPin, INPUT_PULLUP);
pinMode(cwPin, INPUT_PULLUP);
myServo.attach(servoPin);
myServo.write(sc[1]);
statusText=1;
}
void loop() {
// put your main code here, to run repeatedly:
CCWBS = digitalRead(ccwPin);
SBS = digitalRead(stopPin);
CWBS = digitalRead(cwPin);
if(CCWBS == LOW){
servoCommand(0);
int pos = 0;
for(pos =180;pos>=0;pos-=1){
myServo.write(pos);
delay(15);
}
}else if(SBS == LOW){
servoCommand(1);
}else if(CWBS==LOW){
servoCommand(2);
int pos = 0;
for(pos =0;pos<=180;pos+=1){
myServo.write(pos);
delay(15);
}
}
Serial.println(scText[statusText]);
delay(50);
}
void servoCommand(int n){
statusText = n;
myServo.write(sc[n]);
Serial.println("Going to....");
Serial.print(scText[n]);
Serial.print("(");
Serial.print(sc[n]);
Serial.print(")");
}