// Define LEDC parameters const int servoPin = 27; // GPIO pin connected to servo signal wire const int ledChannel = 0; // PWM channel (0-15) const int pwmFreq = 50; // Servo PWM frequency (50 Hz -> 20ms) const int pwmResolution = 12; // Resolution in bits (up to 16 bits) const float pwm2us = 4096; // Duty limits for standard servo (adjust if needed) const int dutyMin = pwm2us * 0.5f / 20.0f; // ~0.5ms pulse (2.5% duty at 16-bit) const int dutyMax = pwm2us * 2.5f / 20.0f; // ~2.5ms pulse (12.5% duty at 16-bit) void setup() { Serial.begin(115200); // Configure LEDC for PWM ledcSetup(ledChannel, pwmFreq, pwmResolution); ledcAttachPin(servoPin, ledChannel); float angle = 90.0f; int duty = map(angle, 0, 180, dutyMin, dutyMax); ledcWrite(ledChannel, duty); } void loop() { for (int i = 0; i < 180; i++) { // Linearly interpolate between min and max duty int duty = map(i, 0, 180, dutyMin, dutyMax); Serial.print("Degrees\t"); Serial.print(i); Serial.print("\t"); Serial.print("Duty\t"); Serial.print(duty); Serial.print("\t"); Serial.print(512); Serial.print("\t"); Serial.println(-2); ledcWrite(ledChannel, duty); delay(20); // Wait for servo to move } for (int i = 180; i > 0; i--) { // Linearly interpolate between min and max duty int duty = map(i, 1, 180, dutyMin, dutyMax); Serial.print("Degrees\t"); Serial.print(i); Serial.print("\t"); Serial.print("Duty\t"); Serial.print(duty); Serial.print("\t"); Serial.print(512); Serial.print("\t"); Serial.println(-2); ledcWrite(ledChannel, duty); delay(20); // Wait for servo to move } }