#define PWM_PIN 5 // GPIO pin for PWM
#define PWM_FREQ 5000 // PWM frequency (Hz)
#define PWM_CHANNEL 0 // PWM channel
#define PWM_RES 8 // PWM resolution (8 bits: 0-255)
void setup() {
ledcSetup(PWM_CHANNEL, PWM_FREQ, PWM_RES); // Configure PWM channel
ledcAttachPin(PWM_PIN, PWM_CHANNEL); // Attach pin to channel
}
void loop() {
// Example: gradually increase and decrease speed/brightness
for (int duty = 0; duty <= 255; duty++) {
ledcWrite(PWM_CHANNEL, duty); // Set duty cycle (0-255)
delay(10);
}
for (int duty = 255; duty >= 0; duty--) {
ledcWrite(PWM_CHANNEL, duty);
delay(10);
}
}