Color Palette Crossfades Example code showing how to continuously cross-fade between multiple color palettes

Well, if RAM is the issue, switching to a Mega will probably help. What’s odd is that it works fine for a while. You maybe be very close to some limit or other most of the time and then sometimes step over it.

Or maybe it’s something else, like a divide by zero. I’ll look at the code.

Thanks! I really appreciate it :slight_smile:

You’ll probably notice I just squeezed all the palette code right into the timer. In my old code (without your new blending code) I had separate void references for each palette, but for some reason, doing the same thing when adding in the blending code would not compile. Couldn’t really figure out why, so I just lost the reference and stuck it all in the timer section. I just really wanted those color combos! They look so pretty :smiley:

Also, I should add, when I changed the timer multiplier value to a larger number to have a each palette stay showing for a longer period of time, the glitch would happen within the first palette and reset, instead of the third palette. That might give you a better idea of why it’s happening?

Just as a couple of side notes to help you stay sane and to make your code a bit more compact, here are two items that might be of interest to you:

  1. there are #defines for HUE_RED, HUE_ORANGE, HUE_YELLOW, HUE_GREEN, HUE_AQUA, HUE_BLUE, HUE_PURPLE, and HUE_PINK. so if you want to use those instead of 0, 32, 64, etc., you can. Your choice, makes no difference to the compiler.

  2. you can construct a palette with an RGB gradient just by specifying two endpoints, e.g.
    pal = CRGBPalette16( CHSV(0,255,0), CHSV(0,255,255));
    You can also specify up to four points along the gradient:
    pal = CRGBPalette16( CHSV(0,255,0), CHSV(0,255,255), CHSV(32, 255,255), CHSV(32,255,0));
    If you construct a CRGBPalette16 this way, it makes gradients through RGB color space. If you construct a CHSVPalette16 this way, it makes gradients through HSV color space. (You can assign a CHSVPalette16 into a CRGBPalette16; it’ll convert the HSV palette entries to RGB palette entries) :
    pal = CHSVPalette16( CHSV( 0, 255, 0), CHSV( 64, 255, 255), CHSV( 128, 255, 0) );

These compactions may or may not help with memory, but they probably will help you express your designs with less code.

Wow thanks! Personally, numbers are easier for me, just how my brain thinks. But I definitely did NOT know that I could just specify two points and the program would automatically blend everything in between. Maybe that actually will help with the RAM? Won’t know until I’ll try it!

It will help … a little. Passing fewer arguments on the stack takes less RAM. (e.g., passing 16 CRGB colors = 48 bytes of stack space.)

But its important to remember that the AVR is a “Harvard Architecture” chip – meaning that RAM and program storage memory are totally distinct. Making the program smaller does not (automatically, by itself) free up any more RAM. This is UNlike all contemporary von Neumann architecture CPUs (e.g., Intel, SPARC, etc., etc.), where program and data both share the same pool of memory (RAM).

Play around , and let us know what you find! You might want to start a new thread for the discussion, too, just to keep things better organized, but here is OK for now.

Thanks, will do. I understand what you mean. But I might get lucky, since the program seems like it’s right on the edge of working. If I get it working, I’ll make a new post with a demo video and the final code. If it doesn’t work, wait a few days and I’ll try with the 2560 Mega and post then :smiley:

I really appreciate all your time and help Mark!

Hey everyone, i’ve downloaded the fastLED 3.1 branch and renamed it as fastLED and put in the libraries folder. I’m just getting a bunch of errors. Help!

Hi Mark, This is pretty sweet! I was able to get it running and define my own palettes without difficulty. My question is: Can this work with palettes defined with 16 entries but interpolated across 220 leds? I haven’t been able to get this interpolation across the 220 led array to work. Do I just need to define palettes with 220 entries? Thanks for your advice!

Hey @Rick_Snow ! Would you start a new question thread, and post some of your code, and we’ll see what we can do! (Should be pretty straightforward.)

Hi @Mark_Kriegsman , would this same concept work for 256 Palettes? It looks like a fairly straightforward update to make this work for those, but figured I’d check with you and see if there’s anything I’m not considering.