#include <ESP32Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(18); // attaches the servo on pin 18 to the servo object
}
void loop() {
int potValue = analogRead(A0); // read the value from the potentiometer
int servoPos = map(potValue, 0, 1023, 0, 180); // map the potentiometer value to servo position (0-180)
myservo.write(servoPos); // tell servo to go to the mapped position
delay(15); // waits 15ms for the servo to reach the position
}