LEDCFade not stoppable, workarount to a assign a new fade-target
Posted: Thu Nov 14, 2024 2:32 pm
ARDUINO ESP-Board 2.0.18
I have a callback-routine which is called when the led switches ON or OFF or a new brightness (a slider in the Alexa-App is moved around. The
bool ledcFade(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms);
stucks if it is called again before the fade ends.
the workaround is calling a ledcWrite() with the actual duty cycle always before new ledcFade()
I have a callback-routine which is called when the led switches ON or OFF or a new brightness (a slider in the Alexa-App is moved around. The
bool ledcFade(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms);
stucks if it is called again before the fade ends.
Code: Select all
callback(newbrightness)
{
ledcFade(port_LED_l1, ledcRead(port_LED_l1), newbrightness, FADETIME_MS); // fade 3 secs
}
Code: Select all
callback(newbrightness)
{
ledcWrite(port_LED_l1, ledcRead(port_LED_l1)); // init, if a fade is running it helps not to get stuck
ledcFade(port_LED_l1, ledcRead(port_LED_l1), newbrightness, FADETIME_MS); // fade 3 secs
}