#include <Servo.h>
Servo myServo;
const int servoPin = 3;
const int potPin = A0;
const int switchPin = 8;
void setup() {
myServo.attach(servoPin);
pinMode(switchPin, INPUT);
}
void loop() {
int switchState = digitalRead(switchPin);
if (switchState == HIGH) {
int potValue = analogRead(potPin);
int servoAngle = map(potValue, 0, 1023, 0, 180);
myServo.write(servoAngle);
delay(15);
}
else {
myServo.write(0);
}
}