#include <ESP32Servo.h>
#define PIN_SERVO 15
int switchmode=0;
Servo myServo;
void setup() {
Serial.begin(9600);
myServo.attach(PIN_SERVO);
pinMode(25,INPUT);
pinMode(26,INPUT);
}
void loop() {
int analogValue = analogRead(PIN_SERVO);
int angle = map(analogValue, 0, 1023, 0, 180);
myServo.write(angle);
switchmode=digitalRead(25);
if(switchmode==HIGH)
{
if (angle == 0)
angle = 90;
else if (angle == 90)
angle = 0;
Serial.print("The button is pressed => rotate servo to ");
Serial.print(angle);
Serial.println("°");
myServo.write(angle);
}
}