It’s not required to be defined like that. Here’s a function that makes a palette with random colors each time it’s called.
// This function fills the palette with totally random colors.
void SetupTotallyRandomPalette()
{
for( int i = 0; i < 16; i++) {
currentPalette[i] = CHSV( random8(), 255, random8());
}
}
You could make a function that uses two colors you pass to it.
What if you don’t want to define all 16 points? How can you make it interpolate between fewer than 16 points? Whenever I try this with fewer than 16 points the ones in between just become black. @marmil
I found this seems to work. If you use the DEFINE_GRADIENT_PALETTE (which is really just array of bytes) you can’t change elements of the array since it’s in read only memory.
Like the macro, the first byte of each four is the anchor point of the color described by the next 3 bytes. The first byte of the last four bytes needs to be 255.
//myPal = heatmap_gp;
uint8_t xyz[12];
memset(xyz, 0, sizeof(xyz));
xyz[0] = 0; // anchor of first color - must be zero
xyz[1] = 255;
xyz[2] = 0;
xyz[3] = 0;
xyz[4] = 128; // anchor - value between 1 and 254
xyz[5] = 255;
xyz[6] = 255;
xyz[7] = 0;
xyz[8] = 255; // anchor of last color - must be 255
xyz[9] = 255,
xyz[10] = 0;
xyz[11] = 255;
myPal = xyz;
for (int p = 0; p < 256; p++)
leds[p] = ColorFromPalette(myPal, p, 255, NOBLEND);
I like how this looks to work @Mike_Brown1 . I tried to put this into a program and test on a Teensy 3.0 but couldn’t get it to upload. Do you have a working example?
@Daniel_Heppner Are you only looking to use two colors, or something between 2 and 16?
@marmil Between 2 and 16. @Mike_Brown1 That looks okay but a little funky looking. I guess I could write a wrapper function for that. I would like to use CRGB named values to make things easier.