#include <Servo.h>
Servo myServo;
const int buttonPins[5] = {2, 3, 4, 5, 6}; // Button pins
const int angles[5] = {90, 45, 0, -45, -90}; // Corresponding angles
void setup() {
myServo.attach(9); // Attach servo to pin 9
for (int i = 0; i < 5; i++) {
pinMode(buttonPins[i], INPUT_PULLUP); // Set button pins as input with pull-up resistors
}
}
void loop() {
for (int i = 0; i < 5; i++) {
if (digitalRead(buttonPins[i]) == LOW) { // Check if button is pressed
myServo.write(angles[i]); // Move servo to the respective angle
delay(500); // Debounce delay
}
}
}