#include <ESP32Servo.h> // เรียกใช้ไลบรารีสำหรับเซอร์โวมอเตอร์
const int servopin =18;
const int potPin = 2;
Servo servo;
void setup() {
servo.attach(servopin, 500, 2400);
pinMode(potPin, INPUT);
}
void loop() {
int potValue = analogRead(potPin);
int angle = map(potValue, 0, 4095, 0, 180);
servo.write(angle);
delay(15); // หน่วงเวลาเล็กน้อยเพื่อการเคลื่อนไหวที่ลื่นไหล
}