#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int buttonPin3 = 4;
const int buttonPin4 = 5;
const int buttonPin5 = 6;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int angle1 = 0; // Variable to hold servo1 angle
int angle2 = 0; // Variable to hold servo2 angle
int angle3 = 0; // Variable to hold servo3 angle
int angle4 = 0; // Variable to hold servo4 angle
int angle5 = 0; // Variable to hold servo5 angle
void setup() {
servo1.attach(9); // Attaching servo1 to pin 9
servo2.attach(10); // Attaching servo2 to pin 10
servo3.attach(11); // Attaching servo3 to pin 11
servo4.attach(12); // Attaching servo4 to pin 12
servo5.attach(13); // Attaching servo5 to pin 13
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buttonPin5, INPUT);
digitalWrite(buttonPin1, HIGH); // Enable internal pull-up resistor for button1
digitalWrite(buttonPin2, HIGH); // Enable internal pull-up resistor for button2
digitalWrite(buttonPin3, HIGH); // Enable internal pull-up resistor for button3
digitalWrite(buttonPin4, HIGH); // Enable internal pull-up resistor for button4
digitalWrite(buttonPin5, HIGH); // Enable internal pull-up resistor for button5
}
void loop() {
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState5 = digitalRead(buttonPin5);
if (buttonState1 == LOW) {
angle1 = 180;
} else {
angle1 = 0;
}
if (buttonState2 == LOW) {
angle2 = 180;
} else {
angle2 = 0;
}
if (buttonState3 == LOW) {
angle3 = 180;
} else {
angle3 = 0;
}
if (buttonState4 == LOW) {
angle4 = 180;
} else {
angle4 = 0;
}
if (buttonState5 == LOW) {
angle5 = 180;
} else {
angle5 = 0;
}
servo1.write(angle1);
servo2.write(angle2);
servo3.write(angle3);
servo4.write(angle4);
servo5.write(angle5);
delay(20); // Delay for servo movement (adjust as needed)
}