FastLED 3.9.15
Loading...
Searching...
No Matches

◆ DEFINE_GRADIENT_PALETTE

#define DEFINE_GRADIENT_PALETTE ( X)
Value:
FL_ALIGN_PROGMEM \
extern const ::TProgmemRGBGradientPalette_byte X[] FL_PROGMEM =
#define FL_PROGMEM
PROGMEM keyword for storage.

Defines a static RGB palette very compactly using a series of connected color gradients.

For example, if you want the first 3/4ths of the palette to be a slow gradient ramping from black to red, and then the remaining 1/4 of the palette to be a quicker ramp to white, you specify just three points: the starting black point (at index 0), the red midpoint (at index 192), and the final white point (at index 255). It looks like this:

index: 0 192 255
|----------r-r-r-rrrrrrrrRrRrRrRrRRRR-|-RRWRWWRWWW-|
color: (0,0,0) (255,0,0) (255,255,255)

Here's how you'd define that gradient palette using this macro:

DEFINE_GRADIENT_PALETTE( black_to_red_to_white_p ) {
0, 0, 0, 0, /* at index 0, black(0,0,0) */
192, 255, 0, 0, /* at index 192, red(255,0,0) */
255, 255, 255, 255 /* at index 255, white(255,255,255) */
};
#define DEFINE_GRADIENT_PALETTE(X)
Defines a static RGB palette very compactly using a series of connected color gradients.
Definition colorutils.h:69

This format is designed for compact storage. The example palette here takes up just 12 bytes of PROGMEM (flash) storage, and zero bytes of SRAM when not currently in use.

To use one of these gradient palettes, simply assign it into a CRGBPalette16 or a CRGBPalette256, like this:

CRGBPalette16 pal = black_to_red_to_white_p;
RGB color palette with 16 discrete values.

When the assignment is made, the gradients are expanded out into either 16 or 256 palette entries, depending on the kind of palette object they're assigned to.

Warning
The last "index" position MUST be 255! Failure to end with index 255 will result in program hangs or crashes.
Warning
At this point, these gradient palette definitions MUST be stored in PROGMEM on AVR-based Arduinos. If you use the DEFINE_GRADIENT_PALETTE macro, this is taken of automatically.

TProgmemRGBGradientPalette_byte must remain in the global namespace.

Definition at line 69 of file colorutils.h.

69#define DEFINE_GRADIENT_PALETTE(X) \
70 FL_ALIGN_PROGMEM \
71 extern const ::TProgmemRGBGradientPalette_byte X[] FL_PROGMEM =