#include <Servo.h>
Servo myservo;
const int switchPin = 5;
const int servoPin = A0;
int switchVal;
int currentServoPos;
int servoPos = 7200;
void setup() {
// put your setup code here, to run once:
pinMode(switchPin, INPUT);
myservo.attach(servoPin);
Serial.begin(9600);
}
void ReadPins()
{
switchVal = digitalRead(switchPin);
currentServoPos = myservo.read();
Serial.print("Servo State:");
Serial.println(servoPos);
Serial.print("switch State:");
Serial.println(switchVal);
}
void loop() {
while(switchVal == 1)
{
ReadPins();
myservo.writeMicroseconds(servoPos);
servoPos += 100;
if(servoPos >= 32680)
{
servoPos = 7200;
}
ReadPins();
}
ReadPins();
if(currentServoPos > 0)
{
myservo.write(0);
}
}