Hello!
I send a gradient over from my app which is formatted like this:
90#4153083/0#14355470/100#
The first number is the direction. Every set of hashtags after that includes a 24bit RGB value and a number (0 to 100) to indicate its percent in the gradient.
I wanted to convert this to a FastLED palette to display on my led strips. I did so following this example.
The code to add the colours and anchors to an array is this:
rawp[index] = anch;
rawp[index + 1] = (rgb >> 16) & 0xFF;
rawp[index + 2] = (rgb >> 8) & 0xFF;
rawp[index + 3] = rgb & 0xFF;
rawp
is a uint8_t
array. I set the first value to the anchor point, and the next 3 to the r,g,b values (these are split out of the string via strtok
) I then increment index
by 4.
To display it I first convert the array to a CRGBPalette256 like so:
CRGBPalette256 pal;
pal = m_cd.rawPal;
I then loop over all leds and use ColorFromPalette
leds[j] = ColorFromPalette(pal, j * 255 / (m_clc->size() - 1), m_cd.bri, LINEARBLEND);
However, when I run this it displays a totally wrong gradient (there is a gradient it just shows two wrong colours). I double checked the RGB values that get unpacked (from the 24bit int) and they match what is shown on my app. I tried 2 standard FastLED palettes and they displayed correctly. I have also checked things like making sure I have allocated the correct size for the "rawp" array.
Does anyone know why the custom palette would not display correctly? (I do have my colour order set correctly, and a common ground)