#include <ESP32Servo.h>
Servo myservo; // create servo object to control a servo
int servoPin = 18; // Pin for servo control (digital out)
int potPin = 34; //Pin to control Potentiometer (analog input)
int ADC_Max = 4096; // This is the default ADC max value on the ESP32 (12 bit ADC width); 8 bits = 255, 10 bit= 1024 & 12 bit = 4096
// Possible PWM GPIO pins o on ESP32: 0(used by on-board button),2,4,5,(used by on-board LED), 12-19, 21-23,25-27,32-33
// Possible ADC pins on ESP32; 0,2,4,12-15,32-39,34-39 are recommended for analog input
int val; // variable to read he value from the analog pin
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32 Potenmeter and Servo w/ Library use!");
//Allow allocation of all timers
ESP32PWM::allocateTimer(0);
ESP32PWM::allocateTimer(1);
ESP32PWM::allocateTimer(2);
ESP32PWM::allocateTimer(3);
myservo.setPeriodHertz(50); //standars 50Hz servo & Period Pulse of 20ms
myservo.attach(servoPin, 500, 2500); //attaches the servo on pin 18 to the servo Objecgt
//using default min/max of 500ms (0 pos) and 2500ms (180 pos), different servos requie different settings
}
void loop() {
val = analogRead(potPin);
val = map(val, 0, ADC_Max, 0, 180);
myservo.write(val);
Serial.println(val);
delay(200);
}