#define pot 27
#include <ESP32Servo.h>
Servo myservo;
int value = 0;
int angle = 0;
void setup() {
Serial.begin(115200);
myservo.attach(16, 500, 2400);//us
}
void loop() {
value = analogRead(pot);
angle = map(value, 0, 4095, 0, 180);
myservo.write(angle); //angle degree
Serial.print("Pot_Value = ");
Serial.print(value); //defualt value
Serial.print(", Angle = "); Serial.print(angle);
Serial.print(", feedback = "); Serial.println(myservo.read());
}
//Servo function (Method)-----------------
//attach() ប្រកាសបើកជើង និងហ្វ្រេកង់
//dettach() ប្រកាសបិទជើង និងហ្វ្រេកង់
//write() បញ្ជាមុំ 0-180 ដឺក្រេ
//writeMicroseconds() បញ្ជាមុំ បម្រែបម្រួលញឹក
//read(); អានតម្លៃមុំមកពី Servo Motor