#include <ESP32Servo.h>
const int buttonPin = 2; // Pin connected to the pushbutton
const int servoPin = 14; // Pin connected to the servo motor
Servo myServo;
int buttonState = 0; // Variable for reading the pushbutton status
int lastButtonState = 0; // Variable to store the previous pushbutton state
int servoPosition = 0; // Variable to store the current servo position
void setup() {
pinMode(buttonPin, INPUT);
myServo.attach(servoPin);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH && lastButtonState == LOW) {
rotateServo();
}
lastButtonState = buttonState;
}
void rotateServo() {
myServo.write(90); // Rotate the servo to 90 degrees
delay(1000); // Wait for 1 second
myServo.write(0); // Return the servo to its initial position (0 degrees)
delay(1000); // Wait for 1 second
}