FastLED 3.9.15
Loading...
Searching...
No Matches
ColorPalette.ino
Go to the documentation of this file.
1// @filter: (board is not stm32f103cb)
2
6
7#include <FastLED.h>
8
9#define LED_PIN 5
10#define NUM_LEDS 50
11#define BRIGHTNESS 64
12#define LED_TYPE WS2811
13#define COLOR_ORDER GRB
15
16#define UPDATES_PER_SECOND 100
17
18// This example shows several ways to set up and use 'palettes' of colors
19// with FastLED.
20//
21// These compact palettes provide an easy way to re-colorize your
22// animation on the fly, quickly, easily, and with low overhead.
23//
24// USING palettes is MUCH simpler in practice than in theory, so first just
25// run this sketch, and watch the pretty lights as you then read through
26// the code. Although this sketch has eight (or more) different color schemes,
27// the entire sketch compiles down to about 6.5K on AVR.
28//
29// FastLED provides a few pre-configured color palettes, and makes it
30// extremely easy to make up your own color schemes with palettes.
31//
32// Some notes on the more abstract 'theory and practice' of
33// FastLED compact palettes are at the bottom of this file.
34
35
36
37CRGBPalette16 currentPalette;
38TBlendType currentBlending;
39
40extern CRGBPalette16 myRedWhiteBluePalette;
42
43// If you are using the fastled compiler, then you must declare your functions
44// before you use them. This is standard in C++ and C projects, but ino's are
45// special in that they do this for you. Eventually we will try to emulate this
46// feature ourselves but in the meantime you'll have to declare your functions
47// before you use them if you want to use our compiler.
49void FillLEDsFromPaletteColors(uint8_t colorIndex);
53
54
55void setup() {
56 delay( 3000 ); // power-up safety delay
57 FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
58 FastLED.setBrightness( BRIGHTNESS );
59
61 currentBlending = LINEARBLEND;
62}
63
64
65void loop()
66{
68
69 static uint8_t startIndex = 0;
70 startIndex = startIndex + 1; /* motion speed */
71
72 FillLEDsFromPaletteColors( startIndex);
73
74 FastLED.show();
75 FastLED.delay(1000 / UPDATES_PER_SECOND);
76}
77
78void FillLEDsFromPaletteColors( uint8_t colorIndex)
79{
80 uint8_t brightness = 255;
81
82 for( int i = 0; i < NUM_LEDS; ++i) {
84 colorIndex += 3;
85 }
86}
87
88
89// There are several different palettes of colors demonstrated here.
90//
91// FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,
92// OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
93//
94// Additionally, you can manually define your own color palettes, or you can write
95// code that creates color palettes on the fly. All are shown here.
96
98{
99 uint8_t secondHand = (millis() / 1000) % 60;
100 static uint8_t lastSecond = 99;
101
102 if( lastSecond != secondHand) {
103 lastSecond = secondHand;
104 if( secondHand == 0) { currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; }
105 if( secondHand == 10) { currentPalette = RainbowStripeColors_p; currentBlending = NOBLEND; }
106 if( secondHand == 15) { currentPalette = RainbowStripeColors_p; currentBlending = LINEARBLEND; }
107 if( secondHand == 20) { SetupPurpleAndGreenPalette(); currentBlending = LINEARBLEND; }
108 if( secondHand == 25) { SetupTotallyRandomPalette(); currentBlending = LINEARBLEND; }
109 if( secondHand == 30) { SetupBlackAndWhiteStripedPalette(); currentBlending = NOBLEND; }
110 if( secondHand == 35) { SetupBlackAndWhiteStripedPalette(); currentBlending = LINEARBLEND; }
111 if( secondHand == 40) { currentPalette = CloudColors_p; currentBlending = LINEARBLEND; }
112 if( secondHand == 45) { currentPalette = PartyColors_p; currentBlending = LINEARBLEND; }
113 if( secondHand == 50) { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND; }
114 if( secondHand == 55) { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }
115 }
116}
117
118// This function fills the palette with totally random colors.
120{
121 for( int i = 0; i < 16; ++i) {
122 currentPalette[i] = CHSV( random8(), 255, random8());
123 }
124}
125
126// This function sets up a palette of black and white stripes,
127// using code. Since the palette is effectively an array of
128// sixteen CRGB colors, the various fill_* functions can be used
129// to set them up.
131{
132 // 'black out' all 16 palette entries...
134 // and set every fourth one to white.
139
140}
141
142// This function sets up a palette of purple and green stripes.
144{
145 CRGB purple = CHSV( HUE_PURPLE, 255, 255);
146 CRGB green = CHSV( HUE_GREEN, 255, 255);
147 CRGB black = CRGB::Black;
148
149 currentPalette = CRGBPalette16(
150 green, green, black, black,
151 purple, purple, black, black,
152 green, green, black, black,
153 purple, purple, black, black );
154}
155
156
157// This example shows how to set up a static color palette
158// which is stored in PROGMEM (flash), which is almost always more
159// plentiful than RAM. A static PROGMEM palette like this
160// takes up 64 bytes of flash.
162{
163 CRGB::Red,
164 CRGB::Gray, // 'white' is too bright compared to red and blue
167
168 CRGB::Red,
172
173 CRGB::Red,
174 CRGB::Red,
181};
182
183
184
185// Additional notes on FastLED compact palettes:
186//
187// Normally, in computer graphics, the palette (or "color lookup table")
188// has 256 entries, each containing a specific 24-bit RGB color. You can then
189// index into the color palette using a simple 8-bit (one byte) value.
190// A 256-entry color palette takes up 768 bytes of RAM, which on Arduino
191// is quite possibly "too many" bytes.
192//
193// FastLED does offer traditional 256-element palettes, for setups that
194// can afford the 768-byte cost in RAM.
195//
196// However, FastLED also offers a compact alternative. FastLED offers
197// palettes that store 16 distinct entries, but can be accessed AS IF
198// they actually have 256 entries; this is accomplished by interpolating
199// between the 16 explicit entries to create fifteen intermediate palette
200// entries between each pair.
201//
202// So for example, if you set the first two explicit entries of a compact
203// palette to Green (0,255,0) and Blue (0,0,255), and then retrieved
204// the first sixteen entries from the virtual palette (of 256), you'd get
205// Green, followed by a smooth gradient from green-to-blue, and then Blue.
void setup()
void loop()
#define COLOR_ORDER
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
#define LED_PIN
#define BRIGHTNESS
void SetupTotallyRandomPalette()
TBlendType currentBlending
const TProgmemPalette16 myRedWhiteBluePalette_p
void ChangePalettePeriodically()
#define UPDATES_PER_SECOND
CRGBPalette16 currentPalette
CRGBPalette16 myRedWhiteBluePalette
void FillLEDsFromPaletteColors(uint8_t colorIndex)
void SetupPurpleAndGreenPalette()
void SetupBlackAndWhiteStripedPalette()
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
#define LED_TYPE
@ HUE_GREEN
Green (135°)
Definition hsv.h:101
@ HUE_PURPLE
Purple (270°)
Definition hsv.h:104
CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType)
void fill_solid(CRGB *targetArray, int numToFill, const CRGB &color) FL_NOEXCEPT
Fill a range of LEDs with a solid color.
Definition fill.cpp.hpp:9
#define TProgmemPalette16
Alias for TProgmemRGBPalette16.
#define FL_PROGMEM
PROGMEM keyword for storage.
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:15
fl::hsv8 CHSV
Definition chsv.h:11
fl::CRGB CRGB
Definition crgb.h:25
const TProgmemRGBPalette16 RainbowStripeColors_p
HSV Rainbow colors with alternatating stripes of black.
const TProgmemRGBPalette16 CloudColors_p
Cloudy color palette.
const TProgmemRGBPalette16 PartyColors_p
HSV color ramp: blue, purple, pink, red, orange, yellow (and back).
const TProgmemRGBPalette16 RainbowColors_p
HSV Rainbow.
LIB8STATIC fl::u8 random8() FL_NOEXCEPT
Generate an 8-bit random number.
Definition random8.h:53
@ 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
@ Gray
<div style='background:#808080;width:4em;height:4em;'></div>
Definition crgb.h:556
@ White
<div style='background:#FFFFFF;width:4em;height:4em;'></div>
Definition crgb.h:646
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:510