#include <ESP32Servo.h>
Servo myservo;
const int button1Pin = 12;
const int button2Pin = 13;
void setup() {
myservo.attach(16); // attach the servo on pin 16
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
Serial.begin(115200);
}
void loop() {
if (digitalRead(button1Pin) == LOW) {
// button 1 is pressed, rotate servo to position 1
myservo.write(180);
delay(200);
}
if (digitalRead(button2Pin) == LOW) {
// button 2 is pressed, rotate servo to position 2
myservo.write(0);
delay(200);
}
}