#include <ESP32Servo.h>
Servo myservo; // create servo object to control a servo
// 16 servo objects can be created on the ESP32
int pos = 0; // variable to store the servo position
// Recommended PWM GPIO pins on the ESP32 include 2,4,12-19,21-23,25-27,32-33
int servoPin = 32;
int potPin = 26;
int potValue = 0;
int value = map(0,0,4095,0,180);
void setup() {
Serial.begin(115200);
// Allow allocation of all timers
ESP32PWM::allocateTimer(0);
ESP32PWM::allocateTimer(1);
ESP32PWM::allocateTimer(2);
ESP32PWM::allocateTimer(3);
myservo.setPeriodHertz(50); // standard 50 hz servo
myservo.attach(servoPin, 500, 2500); // attaches the servo on pin 13 to the servo object
// using min/max pulses of 500us and 2500us
// different servos may require different min/max settings
// for an accurate 0 to 180 sweep
}
void loop() {
potValue = analogRead(potPin);
value = map(potValue,0,4095,0,180);
myservo.write(value);
delay(15);
}