Closed kaysond closed 7 months ago
Hmmmm...I don't see where you're blending colors to create the fading effect in your code. Like this line in the WS2812FX::mode_breath(void)
function:
uint32_t color = color_blend(_seg->colors[1], _seg->colors[0], lum);
I would take a different tack. Instead of creating a custom effect, I think I'd use the isCycle() function to detect the end of the breath animation cycle and change color at that point in time. Like this:
void loop() {
ws2812fx.service();
if(ws2812fx.getMode() == FX_MODE_BREATH) {
if(ws2812fx.isCycle()) { // if end of breath cycle, change color
uint32_t newColor = ws2812fx.color_wheel(ws2812fx.random8()); // some random color
ws2812fx.setColor(newColor);
}
}
}
I don't see where you're blending colors
I was wondering why that was there... I thought its a one-color effect so I just set the one color and dimmed using setBrightness
, assuming that color_blend
effectively does the same thing if the second color is 0.
I think I'd use the isCycle()
I don't think that will quite work the way I want because it'll instantly swap between the two colors at the end of the cycle, right? Because there's the pause in breath
. I want to make it fade to nothing before switching colors so there's no instant color switch.
One thing you can do if you want to fade to black is to turn on Gamma Correction. when you setup the segment. Gamma correction will skew dim colors dimmer and bright colors brighter. Very dIm colors will be black. It's a bit of a hack, but might give you want you want.
ws2812fx.setSegment(0, 0, LED_COUNT - 1, FX_MODE_BREATH, RED, 1000, GAMMA);
Otherwise, I think you're right, you'll have to develop a custom effect.
So the gamma didn't work, but turns out my issue was that I didn't know you have to do both setCustomMode()
and setMode(FX_MODE_CUSTOM)
. Now I've got it working!
I'm trying to create a custom mode that is the same as breath, except it does it once as one color, then switches to another color, repeat. So my first attempt is to essentially copy
mode_breath
but grab segment info from the public segment/runtime getters. Unfortunately, I get a static dim color, and no animation. It seems likecounter_mode_step
is getting reset by something, but I couldn't figure out what.What am I doing wrong here? Or maybe there's an entirely better way entirely to do this? TIA.