#define servoPin 12 // GPIO pin connected to the servo
#define freq 50 // PWM frequency in Hz
#define channel 1 // PWM channel (0-15)
#define resolution 16 // PWM resolution (bits)
void setup() {
// Configure LEDC to generate PWM on the specified pin
ledcSetup(channel, freq, resolution);
ledcAttachPin(servoPin, channel);
}
// Function to set the servo position in microseconds
void write_Servo_micros(int micro_sec) {
long dutyCycle = map(micro_sec, 500, 2500, 2000, 8000);
ledcWrite(channel, dutyCycle);
}
void loop() {
// Move the servo to the minimum position
write_Servo_micros(600);
delay(500); // Wait for 1 second
// Move the servo to the maximum position
write_Servo_micros(2400);
delay(500); // Wait for 1 second
}