#include <Servo.h>
const int switch1Pin = 13; // Pin for switch 1
const int switch2Pin = 12; // Pin for switch 2
const int switch3Pin = 11; // Pin for switch 3
const int servoPin = 9; // Pin for the servo motor
Servo servo;
void setup() {
servo.attach(servoPin); // Attaches the servo to the specified pin
pinMode(switch1Pin, INPUT_PULLUP); // Sets switch 1 pin as input with internal pull-up resistor
pinMode(switch2Pin, INPUT_PULLUP); // Sets switch 2 pin as input with internal pull-up resistor
pinMode(switch3Pin, INPUT_PULLUP); // Sets switch 3 pin as input with internal pull-up resistor
}
void loop() {
int switch1State = digitalRead(switch1Pin); // Read the state of switch 1
int switch2State = digitalRead(switch2Pin); // Read the state of switch 2
int switch3State = digitalRead(switch3Pin); // Read the state of switch 3
if (switch1State == LOW) {
// Switch 1 is pressed, instruct the servo to -90 degrees (end of clockwise direction)
servo.write(0);
}
else if (switch2State == LOW) {
// Switch 2 is pressed, instruct the servo to 0 degrees (middle of rotation)
servo.write(90);
}
else if (switch3State == LOW) {
// Switch 3 is pressed, instruct the servo to +90 degrees (end of counterclockwise direction)
servo.write(180);
}
}