Hi! I have been working with interpolating between color palettes. I have read about defining a 16 color palette which is then interpolated across an array of leds of n elements. I was able to get this to work with 60 leds but now am trying 220 leds and I seem to be getting repetitions of the 16 colors across the 220 instead of a “stretching” of the defined 16 colors across the entire 220. Any advice is greatly appreciated. Here is the code I’ve been working with: http://pastebin.com/TxnSC6sE
Hi Rick,
if you want to spread the 16 colors from your palette over the whole 220 leds, without blending.
You’d have to use this code:
for( int i = 0; i < NUM_LEDS; i++) {
int j = map(i,0,219,0,15);
leds[i] = ColorFromPalette( currentPalette, j, brightness,NOBLEND);
}
Hope this helps.
(Post edited for using the arduino map function instead of self-made made float calculation i*(16/220) )
Rick, try commenting out line 208: colorIndex += 4;
I suspect that was for when you had only 60 LEDs.
Thanks for your advice! I actually just reloaded everything as I sent to you and it seems to be working as it should.
Claude, trying the mapping you advised seemed to send the first color stored in the palette to all leds. Could this be because it can’t use a floating point value for an index? Jason, I commented this out but I don’t think it did anything. I’ve set it to colorIndex += 1 now. I think this is creating the color palette read through the entire array but I’m not totally sure.
Hi Rick,
my bad. The ColorFromPalette requires a value between 0 and 255, and not 0 and 15 like my use of map wrongly does. This change should do the trick:
int j= map(i,0,219,0,255);
If you use NOBLEND in your ColorFromPalette call, this will give you hard edges on the 16 colors spread over your 220 leds, if you use LINEARBLEND you’ll get smooth transition.
Another way of accomplishing the same NOBLEND functionality would be:
int j = map(i,0,219,0,15);
leds[i] = currentPalette[j];