Skip to content

Commit b29d422

Browse files
committed
Create designer_palettes_sunset.ino
1 parent 4c375a1 commit b29d422

File tree

1 file changed

+298
-0
lines changed

1 file changed

+298
-0
lines changed
Lines changed: 298 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,298 @@
1+
2+
#include "FastLED.h"
3+
4+
// ColorWavesWithPalettes
5+
// Animated shifting color waves, with several cross-fading color palettes.
6+
// by Mark Kriegsman, August 2015
7+
//
8+
// Color palettes courtesy of cpt-city and its contributors:
9+
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/
10+
//
11+
// Color palettes converted for FastLED using "PaletteKnife" v1:
12+
// http://fastled.io/tools/paletteknife/
13+
//
14+
15+
16+
#define DATA_PIN SCL
17+
#define LED_TYPE WS2812
18+
#define COLOR_ORDER RBG // If colors are coming out wrong, re-order (RGB, BRG, etc)
19+
#define NUM_LEDS 150 // Change this to reflect the number of LEDs you have
20+
#define BRIGHTNESS 255 // Set Brightness here
21+
22+
CRGB leds[NUM_LEDS];
23+
24+
// ten seconds per color palette makes a good demo
25+
// 20-120 is better for deployment
26+
#define SECONDS_PER_PALETTE 30
27+
28+
29+
void setup() {
30+
delay(1000); // 3 second delay for recovery
31+
32+
// tell FastLED about the LED strip configuration
33+
FastLED.addLeds<LED_TYPE,DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS)
34+
.setCorrection(TypicalLEDStrip) // cpt-city palettes have different color balance
35+
.setDither(BRIGHTNESS < 255);
36+
37+
// set master brightness control
38+
FastLED.setBrightness(BRIGHTNESS);
39+
}
40+
41+
// Forward declarations of an array of cpt-city gradient palettes, and
42+
// a count of how many there are. The actual color palette definitions
43+
// are at the bottom of this file.
44+
extern const TProgmemRGBGradientPalettePtr gGradientPalettes[];
45+
extern const uint8_t gGradientPaletteCount;
46+
47+
// Current palette number from the 'playlist' of color palettes
48+
uint8_t gCurrentPaletteNumber = 0;
49+
50+
CRGBPalette16 gCurrentPalette( CRGB::Black);
51+
CRGBPalette16 gTargetPalette( gGradientPalettes[0] );
52+
53+
54+
55+
56+
// This function draws color waves with an ever-changing,
57+
// widely-varying set of parameters, using a color palette.
58+
void colorwaves( CRGB* ledarray, uint16_t numleds, CRGBPalette16& palette)
59+
{
60+
static uint16_t sPseudotime = 0;
61+
static uint16_t sLastMillis = 0;
62+
static uint16_t sHue16 = 0;
63+
64+
uint8_t sat8 = beatsin88( 87, 220, 250);
65+
uint8_t brightdepth = beatsin88( 341, 225, 255);
66+
uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
67+
uint8_t msmultiplier = beatsin88(147, 23, 60);
68+
69+
uint16_t hue16 = sHue16;//gHue * 256;
70+
uint16_t hueinc16 = beatsin88(113, 300, 1500);
71+
72+
uint16_t ms = millis();
73+
uint16_t deltams = ms - sLastMillis ;
74+
sLastMillis = ms;
75+
sPseudotime += deltams * msmultiplier;
76+
sHue16 += deltams * beatsin88( 400, 5,9);
77+
uint16_t brightnesstheta16 = sPseudotime;
78+
79+
for( uint16_t i = 0 ; i < numleds; i++) {
80+
hue16 += hueinc16;
81+
uint8_t hue8 = hue16 / 256;
82+
uint16_t h16_128 = hue16 >> 7;
83+
if( h16_128 & 0x100) {
84+
hue8 = 255 - (h16_128 >> 1);
85+
} else {
86+
hue8 = h16_128 >> 1;
87+
}
88+
89+
brightnesstheta16 += brightnessthetainc16;
90+
uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
91+
92+
uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
93+
uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
94+
bri8 += (255 - brightdepth);
95+
96+
uint8_t index = hue8;
97+
//index = triwave8( index);
98+
index = scale8( index, 240);
99+
100+
CRGB newcolor = ColorFromPalette( palette, index, bri8);
101+
102+
uint16_t pixelnumber = i;
103+
pixelnumber = (numleds-1) - pixelnumber;
104+
105+
nblend( ledarray[pixelnumber], newcolor, 128);
106+
}
107+
}
108+
109+
// Alternate rendering function just scrolls the current palette
110+
// across the defined LED strip.
111+
void palettetest( CRGB* ledarray, uint16_t numleds, const CRGBPalette16& gCurrentPalette)
112+
{
113+
static uint8_t startindex = 0;
114+
startindex--;
115+
fill_palette( ledarray, numleds, startindex, (256 / NUM_LEDS) + 1, gCurrentPalette, 255, LINEARBLEND);
116+
}
117+
118+
// Gradient palette "bhw1_01_gp", originally from
119+
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw1/tn/bhw1_01.png.index.html
120+
// converted for FastLED with gammas (2.6, 2.2, 2.5)
121+
// Size: 12 bytes of program space.
122+
123+
DEFINE_GRADIENT_PALETTE( bhw1_01_gp ) {
124+
0, 227,101, 3,
125+
117, 194, 18, 19,
126+
255, 92, 8,192};
127+
128+
// Gradient palette "bhw1_07_gp", originally from
129+
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw1/tn/bhw1_07.png.index.html
130+
// converted for FastLED with gammas (2.6, 2.2, 2.5)
131+
// Size: 8 bytes of program space.
132+
133+
DEFINE_GRADIENT_PALETTE( bhw1_07_gp ) {
134+
0, 232, 65, 1,
135+
255, 229,227, 1};
136+
137+
// Gradient palette "bhw1_sunset3_gp", originally from
138+
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw1/tn/bhw1_sunset3.png.index.html
139+
// converted for FastLED with gammas (2.6, 2.2, 2.5)
140+
// Size: 28 bytes of program space.
141+
142+
DEFINE_GRADIENT_PALETTE( bhw1_sunset3_gp ) {
143+
0, 227,237, 56,
144+
33, 186, 67, 1,
145+
71, 163, 21, 1,
146+
81, 157, 13, 1,
147+
188, 39, 21, 18,
148+
234, 12, 7, 4,
149+
255, 12, 7, 4};
150+
151+
// Gradient palette "bhw1_sunset2_gp", originally from
152+
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw1/tn/bhw1_sunset2.png.index.html
153+
// converted for FastLED with gammas (2.6, 2.2, 2.5)
154+
// Size: 20 bytes of program space.
155+
156+
DEFINE_GRADIENT_PALETTE( bhw1_sunset2_gp ) {
157+
0, 255,175, 8,
158+
81, 237, 29, 10,
159+
137, 148, 57, 42,
160+
165, 68, 54, 54,
161+
255, 18, 23, 29};
162+
163+
// Gradient palette "bhw2_sherbet2_gp", originally from
164+
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_sherbet2.png.index.html
165+
// converted for FastLED with gammas (2.6, 2.2, 2.5)
166+
// Size: 32 bytes of program space.
167+
168+
DEFINE_GRADIENT_PALETTE( bhw2_sherbet2_gp ) {
169+
0, 217, 1, 1,
170+
35, 249, 43, 19,
171+
71, 247,125,172,
172+
109, 206, 2, 32,
173+
163, 210, 23, 9,
174+
211, 255,255,255,
175+
232, 252,199, 88,
176+
255, 206,115, 52};
177+
178+
// Gradient palette "bhw2_39_gp", originally from
179+
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_39.png.index.html
180+
// converted for FastLED with gammas (2.6, 2.2, 2.5)
181+
// Size: 28 bytes of program space.
182+
183+
DEFINE_GRADIENT_PALETTE( bhw2_39_gp ) {
184+
0, 2,184,188,
185+
33, 56, 27,162,
186+
66, 56, 27,162,
187+
122, 255,255, 45,
188+
150, 227, 65, 6,
189+
201, 67, 13, 27,
190+
255, 16, 1, 53};
191+
192+
// Gradient palette "bhw2_sunsetx_gp", originally from
193+
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_sunsetx.png.index.html
194+
// converted for FastLED with gammas (2.6, 2.2, 2.5)
195+
// Size: 36 bytes of program space.
196+
197+
DEFINE_GRADIENT_PALETTE( bhw2_sunsetx_gp ) {
198+
0, 42, 55,255,
199+
25, 73,101,242,
200+
89, 115,162,228,
201+
107, 115,162,228,
202+
114, 100, 77,201,
203+
127, 86, 23,174,
204+
142, 190, 32, 24,
205+
171, 210,107, 42,
206+
255, 232,229, 67};
207+
208+
// Gradient palette "bhw2_xc_gp", originally from
209+
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_xc.png.index.html
210+
// converted for FastLED with gammas (2.6, 2.2, 2.5)
211+
// Size: 28 bytes of program space.
212+
213+
DEFINE_GRADIENT_PALETTE( bhw2_xc_gp ) {
214+
0, 4, 2, 9,
215+
58, 16, 0, 47,
216+
122, 24, 0, 16,
217+
158, 144, 9, 1,
218+
183, 179, 45, 1,
219+
219, 220,114, 2,
220+
255, 234,237, 1};
221+
222+
// Gradient palette "bhw2_07_gp", originally from
223+
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_07.png.index.html
224+
// converted for FastLED with gammas (2.6, 2.2, 2.5)
225+
// Size: 24 bytes of program space.
226+
227+
DEFINE_GRADIENT_PALETTE( bhw2_07_gp ) {
228+
0, 92, 1, 1,
229+
26, 153, 20, 5,
230+
79, 232, 72, 12,
231+
127, 220,231, 89,
232+
173, 232, 72, 12,
233+
255, 92, 1, 1};
234+
235+
// Gradient palette "bhw3_32_gp", originally from
236+
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw3/tn/bhw3_32.png.index.html
237+
// converted for FastLED with gammas (2.6, 2.2, 2.5)
238+
// Size: 52 bytes of program space.
239+
240+
DEFINE_GRADIENT_PALETTE( bhw3_32_gp ) {
241+
0, 234,231, 1,
242+
15, 171, 43, 6,
243+
40, 121, 0, 0,
244+
53, 95, 1, 29,
245+
71, 73, 1,168,
246+
94, 38, 63,221,
247+
109, 115, 51,221,
248+
127, 38, 63,221,
249+
147, 73, 1,168,
250+
181, 203, 28, 1,
251+
193, 155, 16, 11,
252+
216, 73, 1,168,
253+
255, 1, 4, 29};
254+
255+
256+
// Single array of defined cpt-city color palettes.
257+
// This will let us programmatically choose one based on
258+
// a number, rather than having to activate each explicitly
259+
// by name every time.
260+
// Since it is const, this array could also be moved
261+
// into PROGMEM to save SRAM, but for simplicity of illustration
262+
// we'll keep it in a regular SRAM array.
263+
//
264+
// This list of color palettes acts as a "playlist"; you can
265+
// add or delete, or re-arrange as you wish.
266+
const TProgmemRGBGradientPalettePtr gGradientPalettes[] = {
267+
bhw3_32_gp,
268+
bhw1_01_gp,
269+
bhw1_07_gp,
270+
bhw1_sunset3_gp,
271+
bhw1_sunset2_gp,
272+
bhw2_sherbet2_gp,
273+
bhw2_39_gp,
274+
bhw2_sunsetx_gp,
275+
bhw2_xc_gp,
276+
bhw2_07_gp,
277+
};
278+
279+
280+
// Count of how many cpt-city gradients are defined:
281+
const uint8_t gGradientPaletteCount =
282+
sizeof( gGradientPalettes) / sizeof( TProgmemRGBGradientPalettePtr );
283+
void loop()
284+
{
285+
EVERY_N_SECONDS( SECONDS_PER_PALETTE ) {
286+
gCurrentPaletteNumber = addmod8( gCurrentPaletteNumber, 1, gGradientPaletteCount);
287+
gTargetPalette = gGradientPalettes[ gCurrentPaletteNumber ];
288+
}
289+
290+
EVERY_N_MILLISECONDS(1500) {
291+
nblendPaletteTowardPalette( gCurrentPalette, gTargetPalette, 16);
292+
}
293+
294+
colorwaves( leds, NUM_LEDS, gCurrentPalette);
295+
296+
FastLED.show();
297+
//FastLED.delay(50);
298+
}

0 commit comments

Comments
 (0)