const int servoPin = 18; // Servo on GPIO 18
// Converts pulse width (in µs) to 16-bit duty cycle
int pulseWidthToDuty(int pulseWidth) {
return (pulseWidth * 65535) / 20000; // 50 Hz -> 20 ms period
}
void setup() {
ledcAttach(servoPin, 50, 16); // PWM on GPIO 18, 50 Hz, 16-bit
}