Skip to content

Commit 3c410fd

Browse files
authored
Merge pull request #2822 from firepixie/Programmable_12v_Cafe_Lights
Create designer_palettes_sunset.ino
2 parents 21123b6 + 1f6540c commit 3c410fd

File tree

1 file changed

+300
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)