FastLED 3.9.15
Loading...
Searching...
No Matches
Color Palettes

Detailed Description

ColorUtils

Functions and class definitions for color palettes.

RGB palettes map an 8-bit value (0-255) to an RGB color.

You can create any color palette you wish; a couple of starters are provided: ForestColors_p, CloudColors_p, LavaColors_p, OceanColors_p, RainbowColors_p, and RainbowStripeColors_p.

Palettes come in the traditional 256-entry variety, which take up 768 bytes of RAM, and lightweight 16-entry varieties. The 16-entry variety automatically interpolates between its entries to produce a full 256-element color map, but at a cost of only 48 bytes of RAM.

Basic operation is like this (using the 16-entry variety):

  1. Declare your palette storage:
    CRGBPalette16 myPalette;
  2. Fill myPalette with your own 16 colors, or with a preset color scheme. You can specify your 16 colors a variety of ways:

    CRGBPalette16 myPalette(
    0x100000,
    0x200000,
    0x400000,
    0x800000,
    CHSV( 30,255,255),
    CHSV( 50,255,255),
    CHSV( 70,255,255),
    CHSV( 90,255,255)
    );
    fl::hsv8 CHSV
    Definition chsv.h:11
    @ Green
    <div style='background:#008000;width:4em;height:4em;'></div>
    Definition crgb.h:558
    @ Red
    <div style='background:#FF0000;width:4em;height:4em;'></div>
    Definition crgb.h:622
    @ Blue
    <div style='background:#0000FF;width:4em;height:4em;'></div>
    Definition crgb.h:512
    @ Yellow
    <div style='background:#FFFF00;width:4em;height:4em;'></div>
    Definition crgb.h:648
    @ Purple
    <div style='background:#800080;width:4em;height:4em;'></div>
    Definition crgb.h:621
    @ Black
    <div style='background:#000000;width:4em;height:4em;'></div>
    Definition crgb.h:510

    Or you can initiaize your palette with a preset color scheme:

    #define RainbowStripesColors_p
    Alias of RainbowStripeColors_p.
  3. Any time you want to set a pixel to a color from your palette, use ColorFromPalette() as shown:

    fl::u8 index = /* any value 0-255 */;
    leds[i] = ColorFromPalette(myPalette, index);
    fl::CRGB leds[NUM_LEDS]
    CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType)
    unsigned char u8
    Definition stdint.h:131

    Even though your palette has only 16 explicily defined entries, you can use an "index" from 0-255. The 16 explicit palette entries will be spread evenly across the 0-255 range, and the intermedate values will be RGB-interpolated between adjacent explicit entries.

    It's easier to use than it sounds.

+ Collaboration diagram for Color Palettes:

Topics

 Gamma Adjustment Functions
 
 Predefined Color Palettes
 Stock color palettes, only included when used.