#include <Servo.h>
Servo myservo;
int switchPin = 2;
void setup() {
myservo.attach(9);
pinMode(switchPin, INPUT_PULLUP);
}
void loop() {
if (digitalRead(switchPin) == HIGH) {
myservo.write(180);
} else {
myservo.write(-180);
}
}#include <Servo.h>
Servo myservo;
int switchPin = 2;
void setup() {
myservo.attach(9);
pinMode(switchPin, INPUT_PULLUP);
}
void loop() {
if (digitalRead(switchPin) == HIGH) {
myservo.write(180);
} else {
myservo.write(-180);
}
}