#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() {
int STOPpin= 4;
int CWpin = 5;
int CCWpin =3;
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(STOPpin, INPUT_PULLUP);
pinMode(CCWpin, INPUT_PULLUP);
pinMode(CWpin, INPUT_PULLUP);
//myservo.attachInterrupt(servoPin);
myservo.attach(servoPin);
myservo.write(sc[1]);
statusText=1;
}
void loop() {
// put your main code here, to run repeatedly:
int STOPpin= 4;
int CWpin = 5;
int CCWpin =3;
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) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
}
Serial.println(scText[statusText]);
delay(50);
}
void servoCommand(int n)
{
statusText=n;
myservo.write(sc[n]);
Serial.print("Going to...");
Serial.print(scText[n]);
Serial.print("(");
Serial.print(sc[n]);
Serial.print(")");
}