// Servo Sweep example for the ESP32
// https://wokwi.com/arduino/projects/323706614646309460
#include <ESP32Servo.h>
const int servoPin = 18;
int potPin =25; // GPIO pin used to connect the potentiometer (analog in)
int ADC_Max = 4096; // This is the default ADC max value on the ESP32 (12 bit ADC width);
// this width can be set (in low-level oode) from 9-12 bits, for a
// a range of max values of 512-4096
int val; // variable to read the value from the analog pin
Servo servo;
void setup() {
servo.attach(servoPin, 500, 2400);
}
int pos = 0;
void loop() {
val = analogRead(potPin); // read the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, ADC_Max, 0, 180); // scale it to use it with the servo (value between 0 and 180)
servo.write(val); // set the servo position according to the scaled value
delay(200);
}