#include <Servo.h>
Servo servo1;
Servo servo2;
int buttonPin = 4; // GPIO pin for the push button
int buttonState = 0;
int lastButtonState = 0;
void setup() {
servo1.attach(13); // Connect servo 1 to GPIO 13
servo2.attach(12); // Connect servo 2 to GPIO 12
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
// When the button is pressed, move the servos to a specific angle
servo1.write(90); // Set the angle for servo 1 (adjust as needed)
servo2.write(90); // Set the angle for servo 2 (adjust as needed)
} else {
// When the button is released, return the servos to their initial position
servo1.write(0);
servo2.write(0);
}
delay(50); // Debounce delay
}
lastButtonState = buttonState;
}