Hello everyone! I have a project where I have 114 neopixels in a rectangle

Hello everyone!

I have a project where I have 114 neopixels in a rectangle and I’d like to use the FastLED palette feature with some of the animations. How do I get the 16 entry palette to look good on a rectangle that’s not evenly divisible by 16? There is a noticeable “break” in the animation at the corner with the beginning and end of the strip.

Thanks in advance!

Steve Hurd

Hi Steve- sorry I didn’t see this before!

So here’s how I’d do it, more or less, first with floating point easier to understand (maybe) math, which is usually too slow for this sort of thing, and then with just integer math:

float paletteAdvancePerPixel = 256.0 / (float)NUM_LEDS;
// in this case, that’ll be 256/114 = 2.2456
// 114 * 2.2456 = 255(and change) Presto!

float paletteIndex = 0;
for( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( myPal, paletteIndex);
paletteIndex += paletteAdvancePerPixel;
}

Here’s how you could do the same thing with ‘fixed point’ math. You have an 8-bit index, but you use a 16-bit value to represent the 8-bit index time 256. This lets you have ‘fractional’ values, which is what you need for this.

uint16_t paletteAdvancePerPixelx256 = (256*256)/NUM_LEDS;
// in this case, that’ll be 65536/114 = 574
// 574/256ths = 2.2421875
// 114 * 2.2421875 = 255(and change) Presto!

uint16_t paletteIndexx256 = 0;
for( int i = 0; i < NUM_LEDS; i++) {
uint8_t index = paletteIndexx256 / 256;
leds[i] = ColorFromPalette( myPal, index);
paletteIndexx256 += paletteAdvancePerPixelx256;
}

This is a great question that you asked, and I hope this helps! Does it get you going more in the right direction?

I think so. I won’t get to try it until I’m home from work tonight, but I really appreciate the help!

I’m assuming if I’m using the palette16 class I just substitute 16 for 256 in the above equations?

Nope! Part of what’s nice about 16-entry palettes is that you can treat them AS IF they had 256 entries-- it interpolates.

Very cool! I’ll try this out tonight and post a video of the results.