-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
This is a fantastic library! I'm using it in my project but I don't quite understand the Fade effect. I can make it work, but it fades for about 1 second and then displays the color statically. I'm trying to make a smooth fade from color to color in a loop and haven't been able to figure it out.
auto controller = PicoLed::addLeds<PicoLed::WS2812B>(pio0, 0, WS2812_PIN, NUM_LEDS, PicoLed::FORMAT_RGB);
controller.setBrightness(LED_BRIGHTNESS);
PicoLed::Fade effectFadeRed(controller, PicoLed::RGB(255,0,0), 1.0);
PicoLed::Fade effectFadeGreen(controller, PicoLed::RGB(0,255,0), 1.0);
PicoLed::Fade effectFadeBlue(controller, PicoLed::RGB(0,0,255), 1.0);
uint colorIndex = 0;
uint colorCount = 3;
bool effectReset = false;
uint32_t effectChangeInterval = 3000; // Change effect every 3 seconds
uint32_t timeNow = to_ms_since_boot( get_absolute_time() );
uint32_t timeNext = timeNow + effectChangeInterval;
while (true) {
switch (colorIndex) {
case 0:
if (effectReset) {
effectReset = false;
effectFadeRed.reset();
}
if (effectFadeRed.animate()) {
controller.show();
}
break;
case 1:
if (effectReset) {
effectReset = false;
effectFadeGreen.reset();
}
if (effectFadeGreen.animate()) {
controller.show();
}
break;
case 2:
if (effectReset) {
effectReset = false;
effectFadeBlue.reset();
}
if (effectFadeBlue.animate()) {
controller.show();
}
break;
}
sleep_ms(5);
// Check for effect change
timeNow = to_ms_since_boot( get_absolute_time() );
if (timeNow > timeNext) {
timeNext = timeNow + effectChangeInterval;
colorIndex = (colorIndex + 1) % colorCount;
effectReset = true;
}
}
What I'm looking for is to fade from red to green and then blue but what it ends up actually doing is just switching between red, green and blue for 3s. If I change effectChangeInterval to 5000 it fades for 1s then stays static color the remaining 4 seconds. So I'm not quite sure what fadeRate is actually doing. Adjusting it had very little effect.
Any advice is appreciated!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels