#include <ESP32Servo.h>
// Define slide potentiometer and servo motor pins
const int slidePotPin = 34; // Slide potentiometer connected to pin 34 (analog input)
const int servoPin = 2; // Servo motor connected to pin 2 (PWM)
Servo servo; // Create a servo object
void setup() {
Serial.begin(9600); // Initialize serial communication
servo.attach(servoPin); // Attach the servo to its pin
}
void loop() {
int slidePotValue = analogRead(slidePotPin); // Read analog value from slide potentiometer
int servoAngle = map(slidePotValue, 0, 4095, 0, 180); // Map potentiometer value to servo angle range (ESP32 ADC resolution is 12 bits)
servo.write(servoAngle); // Set servo position based on potentiometer value
Serial.print("Slide Potentiometer Value: ");
Serial.println(slidePotValue); // Print slide potentiometer value to serial monitor
Serial.print("Servo Angle: ");
Serial.println(servoAngle); // Print servo angle to serial monitor
delay(1000); // Delay for stability
}