├── AudioLogic.h
├── AudioPatterns.h
├── Commands.h
├── Drawing.h
├── Effects.h
├── Fire2012WithPalette.h
├── GradientPalettes.h
├── LICENSE
├── Noise.h
├── Pulse.h
├── README.md
├── Torch.h
├── Wave.h
└── torch.ino
/AudioLogic.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Torch: https://github.com/evilgeniuslabs/torch
3 | * Copyright (C) 2015 Jason Coon
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #define MSGEQ7_STROBE_PIN 2
20 | #define MSGEQ7_RESET_PIN 3
21 | #define MSGEQ7_LEFT_PIN A0
22 | #define MSGEQ7_RIGHT_PIN A1
23 |
24 | const uint8_t bandCount = 7;
25 |
26 | int levelsLeft[bandCount];
27 | int peaksLeft[bandCount];
28 |
29 | int levelsRight[bandCount];
30 | int peaksRight[bandCount];
31 |
32 | static const uint8_t peakDecay = (1024 / MATRIX_HEIGHT) / 4;
33 | bool drawPeaks = true;
34 |
35 | int noiseCorrection[bandCount] = {
36 | // -55, -50, -45, -55, -40, -55, -50,
37 | 0, 0, 0, 0, 0, 0, 0
38 | };
39 |
40 | uint8_t bandOffset = 3;
41 |
42 | uint8_t horizontalPixelsPerBand = MATRIX_WIDTH / (bandCount * 2);
43 |
44 | uint8_t levelsPerVerticalPixel = 63; // 1024 / MATRIX_HEIGHT;
45 |
46 | uint8_t levelsPerHue = 1024 / 256;
47 |
48 | void initializeAudio() {
49 | pinMode(MSGEQ7_LEFT_PIN, INPUT);
50 | pinMode(MSGEQ7_RIGHT_PIN, INPUT);
51 | pinMode(MSGEQ7_RESET_PIN, OUTPUT);
52 | pinMode(MSGEQ7_STROBE_PIN, OUTPUT);
53 | digitalWrite(MSGEQ7_RESET_PIN, LOW);
54 | digitalWrite(MSGEQ7_STROBE_PIN, HIGH);
55 | }
56 |
57 | void readAudio() {
58 | digitalWrite(MSGEQ7_RESET_PIN, HIGH);
59 | digitalWrite(MSGEQ7_RESET_PIN, LOW);
60 |
61 | int levelLeft;
62 | int levelRight;
63 |
64 | for (uint8_t band = 0; band < bandCount; band++) {
65 | digitalWrite(MSGEQ7_STROBE_PIN, LOW);
66 | delayMicroseconds(30);
67 |
68 | levelLeft = analogRead(MSGEQ7_LEFT_PIN);
69 | levelRight = analogRead(MSGEQ7_RIGHT_PIN);
70 | digitalWrite(MSGEQ7_STROBE_PIN, HIGH);
71 |
72 | levelLeft += noiseCorrection[band];
73 | levelRight += noiseCorrection[band];
74 |
75 | // if (levelLeft < 0) levelLeft = 0;
76 | // if (levelLeft > 1023) levelLeft = 1023;
77 | //
78 | // if (levelRight < 0) levelRight = 0;
79 | // if (levelRight > 1023) levelRight = 1023;
80 |
81 | levelsLeft[band] = levelLeft;
82 | levelsRight[band] = levelRight;
83 |
84 | // if (levelLeft >= peaksLeft[band]) {
85 | peaksLeft[band] = levelLeft;
86 | // }
87 | // else if (peaksLeft[band] > 0) {
88 | // peaksLeft[band] = peaksLeft[band] - peakDecay;
89 | // if(peaksLeft[band] < 0) peaksLeft[band] = 0;
90 | // }
91 | //
92 | // if (levelRight >= peaksRight[band]) {
93 | peaksRight[band] = levelRight;
94 | // }
95 | // else if (peaksRight[band] > 0) {
96 | // peaksRight[band] = peaksRight[band] - peakDecay;
97 | // if(peaksRight[band] < 0) peaksRight[band] = 0;
98 | // }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/AudioPatterns.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Torch: https://github.com/evilgeniuslabs/torch
3 | * Copyright (C) 2015 Jason Coon
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | uint16_t analyzerColumns() {
20 | fill_solid(leds, NUM_LEDS, CRGB::Black);
21 |
22 | for (uint8_t bandIndex = 0; bandIndex < bandCount; bandIndex++) {
23 | int levelLeft = levelsLeft[bandIndex];
24 | int levelRight = levelsRight[bandIndex];
25 |
26 | if (drawPeaks) {
27 | levelLeft = peaksLeft[bandIndex];
28 | levelRight = peaksRight[bandIndex];
29 | }
30 |
31 | CRGB colorLeft = ColorFromPalette(palette, levelLeft / levelsPerHue); // CRGB colorLeft = ColorFromPalette(palette, bandIndex * (256 / bandCount));
32 | CRGB colorRight = ColorFromPalette(palette, levelRight / levelsPerHue);
33 |
34 | uint8_t x = bandIndex + bandOffset;
35 | if (x >= MATRIX_WIDTH)
36 | x -= MATRIX_WIDTH;
37 |
38 | drawFastVLine(x, (MATRIX_HEIGHT - 1) - levelLeft / levelsPerVerticalPixel, MATRIX_HEIGHT - 1, colorLeft);
39 | drawFastVLine(x + bandCount, (MATRIX_HEIGHT - 1) - levelRight / levelsPerVerticalPixel, MATRIX_HEIGHT - 1, colorRight);
40 | }
41 |
42 | return 1;
43 | }
44 |
45 | uint16_t analyzerColumnsSolid() {
46 | fill_solid(leds, NUM_LEDS, CRGB::Black);
47 |
48 | for (uint8_t bandIndex = 0; bandIndex < bandCount; bandIndex++) {
49 | int levelLeft = levelsLeft[bandIndex];
50 | int levelRight = levelsRight[bandIndex];
51 |
52 | if (drawPeaks) {
53 | levelLeft = peaksLeft[bandIndex];
54 | levelRight = peaksRight[bandIndex];
55 | }
56 |
57 | CRGB colorLeft = ColorFromPalette(palette, gHue);
58 | CRGB colorRight = ColorFromPalette(palette, gHue);
59 |
60 | uint8_t x = bandIndex + bandOffset;
61 | if (x >= MATRIX_WIDTH)
62 | x -= MATRIX_WIDTH;
63 |
64 | drawFastVLine(x, (MATRIX_HEIGHT - 1) - levelLeft / levelsPerVerticalPixel, MATRIX_HEIGHT - 1, colorLeft);
65 | drawFastVLine(x + bandCount, (MATRIX_HEIGHT - 1) - levelRight / levelsPerVerticalPixel, MATRIX_HEIGHT - 1, colorRight);
66 | }
67 |
68 | return 1;
69 | }
70 |
71 | uint16_t analyzerPixels() {
72 | fill_solid(leds, NUM_LEDS, CRGB::Black);
73 |
74 | for (uint8_t bandIndex = 0; bandIndex < bandCount; bandIndex++) {
75 | int levelLeft = levelsLeft[bandIndex];
76 | int levelRight = levelsRight[bandIndex];
77 |
78 | if (drawPeaks) {
79 | levelLeft = peaksLeft[bandIndex];
80 | levelRight = peaksRight[bandIndex];
81 | }
82 |
83 | CRGB colorLeft = ColorFromPalette(palette, levelLeft / levelsPerHue);
84 | CRGB colorRight = ColorFromPalette(palette, levelRight / levelsPerHue);
85 |
86 | uint8_t x = bandIndex + bandOffset;
87 | if (x >= MATRIX_WIDTH)
88 | x -= MATRIX_WIDTH;
89 |
90 | leds[XY(x, (MATRIX_HEIGHT - 1) - levelLeft / levelsPerVerticalPixel)] = colorLeft;
91 | leds[XY(x + bandCount, (MATRIX_HEIGHT - 1) - levelLeft / levelsPerVerticalPixel)] = colorRight;
92 | }
93 |
94 | return 0;
95 | }
96 |
97 | uint16_t fallingSpectrogram() {
98 | moveDown();
99 |
100 | for (uint8_t bandIndex = 0; bandIndex < bandCount; bandIndex++) {
101 | int levelLeft = levelsLeft[bandIndex];
102 | int levelRight = levelsRight[bandIndex];
103 |
104 | if (drawPeaks) {
105 | levelLeft = peaksLeft[bandIndex];
106 | levelRight = peaksRight[bandIndex];
107 | }
108 |
109 | if (levelLeft <= 8) levelLeft = 0;
110 | if (levelRight <= 8) levelRight = 0;
111 |
112 | CRGB colorLeft;
113 | CRGB colorRight;
114 |
115 | if (currentPaletteIndex < 2) { // invert the first two palettes
116 | colorLeft = ColorFromPalette(palette, 205 - (levelLeft / levelsPerHue - 205));
117 | colorRight = ColorFromPalette(palette, 205 - (levelLeft / levelsPerHue - 205));
118 | }
119 | else {
120 | colorLeft = ColorFromPalette(palette, levelLeft / levelsPerHue);
121 | colorRight = ColorFromPalette(palette, levelRight / levelsPerHue);
122 | }
123 |
124 | uint8_t x = bandIndex + bandOffset;
125 | if (x >= MATRIX_WIDTH)
126 | x -= MATRIX_WIDTH;
127 |
128 | leds[XY(x, 0)] = colorLeft;
129 | leds[XY(x + bandCount, 0)] = colorRight;
130 | }
131 |
132 | return 0;
133 | }
134 |
135 | uint16_t audioFire() {
136 | moveUp();
137 |
138 | for (uint8_t bandIndex = 0; bandIndex < bandCount; bandIndex++) {
139 | int levelLeft = levelsLeft[bandIndex];
140 | int levelRight = levelsRight[bandIndex];
141 |
142 | if (drawPeaks) {
143 | levelLeft = peaksLeft[bandIndex];
144 | levelRight = peaksRight[bandIndex];
145 | }
146 |
147 | if (levelLeft <= 8) levelLeft = 0;
148 | if (levelRight <= 8) levelRight = 0;
149 |
150 | CRGB colorLeft = ColorFromPalette(HeatColors_p, levelLeft / 5);
151 | CRGB colorRight = ColorFromPalette(HeatColors_p, levelRight / 5);
152 |
153 | uint8_t x = bandIndex + bandOffset;
154 | if (x >= MATRIX_WIDTH)
155 | x -= MATRIX_WIDTH;
156 |
157 | leds[XY(x, MATRIX_HEIGHT - 1)] = colorLeft;
158 | leds[XY(x + bandCount, MATRIX_HEIGHT - 1)] = colorRight;
159 | }
160 |
161 | return 0;
162 | }
163 |
164 | uint16_t rainbowAudioNoise() {
165 | static int lastPeak0 = 0;
166 |
167 | noisespeedx = 0;
168 |
169 | if (peaksLeft[0] >= lastPeak0) {
170 | noisespeedx = peaksLeft[0] / 57;
171 | }
172 |
173 | lastPeak0 = peaksLeft[0];
174 |
175 | noisespeedy = 0;
176 | noisespeedz = 0;
177 | noisescale = 30;
178 | colorLoop = 0;
179 | return drawNoise(RainbowColors_p);
180 | }
181 |
182 | uint16_t rainbowStripeAudioNoise() {
183 | static int lastPeak0 = 0;
184 |
185 | noisespeedy = 0;
186 |
187 | if (peaksLeft[0] >= lastPeak0) {
188 | noisespeedy = peaksLeft[0] / 57;
189 | }
190 |
191 | lastPeak0 = peaksLeft[0];
192 |
193 | noisespeedx = 0;
194 | noisespeedz = 0;
195 | noisescale = 20;
196 | colorLoop = 0;
197 | return drawNoise(RainbowStripeColors_p);
198 | }
199 |
200 | uint16_t partyAudioNoise() {
201 | static int lastPeak0 = 0;
202 |
203 | noisespeedx = 0;
204 |
205 | if (peaksLeft[0] >= lastPeak0) {
206 | noisespeedx = peaksLeft[0] / 57;
207 | }
208 |
209 | lastPeak0 = peaksLeft[0];
210 |
211 | noisespeedy = 0;
212 | noisespeedz = 0;
213 | noisescale = 30;
214 | colorLoop = 0;
215 | return drawNoise(PartyColors_p);
216 | }
217 |
218 | uint16_t forestAudioNoise() {
219 | static int lastPeak0 = 0;
220 |
221 | noisespeedx = 0;
222 |
223 | if (peaksLeft[0] >= lastPeak0) {
224 | noisespeedx = peaksLeft[0] / 57;
225 | }
226 |
227 | lastPeak0 = peaksLeft[0];
228 |
229 | noisespeedy = 0;
230 | noisespeedz = 0;
231 | noisescale = 120;
232 | colorLoop = 0;
233 | return drawNoise(ForestColors_p);
234 | }
235 |
236 | uint16_t cloudAudioNoise() {
237 | static int lastPeak0 = 0;
238 |
239 | noisespeedx = 0;
240 |
241 | if (peaksLeft[0] >= lastPeak0) {
242 | noisespeedx = peaksLeft[0] / 57;
243 | }
244 |
245 | lastPeak0 = peaksLeft[0];
246 |
247 | noisespeedy = 0;
248 | noisespeedz = 0;
249 | noisescale = 30;
250 | colorLoop = 0;
251 | return drawNoise(CloudColors_p);
252 | }
253 |
254 | uint16_t fireAudioNoise() {
255 | static int lastPeak0 = 0;
256 | static int lastPeak6 = 0;
257 |
258 | noisespeedx = 0;
259 | noisespeedz = 0;
260 |
261 | if (peaksLeft[0] >= lastPeak0) {
262 | noisespeedx = peaksLeft[0] / 32;
263 | }
264 |
265 | if (peaksLeft[6] >= lastPeak6) {
266 | noisespeedz = peaksLeft[6] / 128;
267 | }
268 |
269 | lastPeak0 = peaksLeft[0];
270 | lastPeak6 = peaksLeft[6];
271 |
272 | noisespeedy = 0;
273 | noisescale = 50;
274 | colorLoop = 0;
275 |
276 | return drawNoise(HeatColors_p, 60);
277 | }
278 |
279 | uint16_t lavaAudioNoise() {
280 | static int lastPeak0 = 0;
281 | static int lastPeak6 = 0;
282 |
283 | noisespeedy = 0;
284 | noisespeedz = 0;
285 |
286 | if (peaksLeft[0] >= lastPeak0) {
287 | noisespeedy = peaksLeft[0] / 32;
288 | }
289 |
290 | if (peaksLeft[6] >= lastPeak6) {
291 | noisespeedz = peaksLeft[6] / 128;
292 | }
293 |
294 | lastPeak0 = peaksLeft[0];
295 | lastPeak6 = peaksLeft[6];
296 |
297 | noisespeedx = 0;
298 | noisescale = 50;
299 | colorLoop = 0;
300 | return drawNoise(LavaColors_p);
301 | }
302 |
303 | uint16_t oceanAudioNoise() {
304 | static int lastPeak0 = 0;
305 |
306 | noisespeedy = 0;
307 |
308 | if (peaksLeft[0] >= lastPeak0) {
309 | noisespeedy = peaksLeft[0] / 57;
310 | }
311 |
312 | lastPeak0 = peaksLeft[0];
313 |
314 | noisespeedx = 0;
315 | noisespeedz = 0;
316 | noisescale = 90;
317 | colorLoop = 0;
318 | return drawNoise(OceanColors_p);
319 | }
320 |
321 | uint16_t blackAndWhiteAudioNoise() {
322 | SetupBlackAndWhiteStripedPalette();
323 | static int lastPeak0 = 0;
324 |
325 | noisespeedy = 0;
326 |
327 | if (peaksLeft[0] >= lastPeak0) {
328 | noisespeedy = peaksLeft[0] / 128;
329 | }
330 |
331 | lastPeak0 = peaksLeft[0];
332 |
333 | noisespeedx = 0;
334 | noisespeedz = 0;
335 | noisescale = 15;
336 | colorLoop = 0;
337 | return drawNoise(blackAndWhiteStripedPalette);
338 | }
339 |
340 | uint16_t blackAndBlueAudioNoise() {
341 | SetupBlackAndBlueStripedPalette();
342 | static int lastPeak0 = 0;
343 |
344 | noisespeedx = 0;
345 |
346 | if (peaksLeft[0] >= lastPeak0) {
347 | noisespeedx = peaksLeft[0] / 57;
348 | }
349 |
350 | lastPeak0 = peaksLeft[0];
351 |
352 | noisespeedy = 0;
353 | noisespeedz = 0;
354 | noisescale = 45;
355 | colorLoop = 0;
356 | return drawNoise(blackAndBlueStripedPalette);
357 | }
358 |
--------------------------------------------------------------------------------
/Commands.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Torch: https://github.com/evilgeniuslabs/torch
3 | * Copyright (C) 2015 Jason Coon
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef IrCodes_H
20 | #define IrCodes_H
21 |
22 | enum class InputCommand {
23 | None,
24 | Up,
25 | Down,
26 | Left,
27 | Right,
28 | Select,
29 | Brightness,
30 | PlayMode,
31 | Power,
32 | BrightnessUp,
33 | BrightnessDown,
34 | CyclePalette,
35 | NextPalette,
36 | PreviousPalette,
37 |
38 | Pattern1,
39 | Pattern2,
40 | Pattern3,
41 | Pattern4,
42 | Pattern5,
43 | Pattern6,
44 | Pattern7,
45 | Pattern8,
46 | Pattern9,
47 | Pattern10,
48 | Pattern11,
49 | Pattern12,
50 |
51 | RedUp,
52 | RedDown,
53 | GreenUp,
54 | GreenDown,
55 | BlueUp,
56 | BlueDown,
57 |
58 | Red,
59 | RedOrange,
60 | Orange,
61 | YellowOrange,
62 | Yellow,
63 |
64 | Green,
65 | Lime,
66 | Aqua,
67 | Teal,
68 | Navy,
69 |
70 | Blue,
71 | RoyalBlue,
72 | Purple,
73 | Indigo,
74 | Magenta,
75 |
76 | White,
77 | Pink,
78 | LightPink,
79 | BabyBlue,
80 | LightBlue,
81 | };
82 |
83 | // IR Raw Key Codes for SparkFun remote
84 | #define IRCODE_SPARKFUN_POWER 0x10EFD827 // 284153895
85 | #define IRCODE_SPARKFUN_A 0x10EFF807 //
86 | #define IRCODE_SPARKFUN_B 0x10EF7887
87 | #define IRCODE_SPARKFUN_C 0x10EF58A7
88 | #define IRCODE_SPARKFUN_UP 0x10EFA05F // 284139615
89 | #define IRCODE_SPARKFUN_LEFT 0x10EF10EF
90 | #define IRCODE_SPARKFUN_SELECT 0x10EF20DF
91 | #define IRCODE_SPARKFUN_RIGHT 0x10EF807F
92 | #define IRCODE_SPARKFUN_DOWN 0x10EF00FF
93 | #define IRCODE_SPARKFUN_HELD 0xFFFFFFFF
94 |
95 | // IR Raw Key Codes for Adafruit remote
96 | #define IRCODE_ADAFRUIT_HELD 0x7FFFFFFF // 4294967295
97 | #define IRCODE_ADAFRUIT_VOLUME_UP 0x00FD40BF // 16597183
98 | #define IRCODE_ADAFRUIT_PLAY_PAUSE 0x00FD807F // 16613503
99 | #define IRCODE_ADAFRUIT_VOLUME_DOWN 0x00FD00FF // 16580863
100 | #define IRCODE_ADAFRUIT_SETUP 0x00FD20DF // 16589023
101 | #define IRCODE_ADAFRUIT_UP 0x00FDA05F // 16621663
102 | #define IRCODE_ADAFRUIT_STOP_MODE 0x00FD609F // 16605343
103 | #define IRCODE_ADAFRUIT_LEFT 0x00FD10EF // 16584943
104 | #define IRCODE_ADAFRUIT_ENTER_SAVE 0x00FD906F // 16617583
105 | #define IRCODE_ADAFRUIT_RIGHT 0x00FD50AF // 16601263
106 | #define IRCODE_ADAFRUIT_0_10_PLUS 0x00FD30CF // 16593103
107 | #define IRCODE_ADAFRUIT_DOWN 0x00FDB04F // 16625743
108 | #define IRCODE_ADAFRUIT_BACK 0x00FD708F // 16609423
109 | #define IRCODE_ADAFRUIT_1 0x00FD08F7 // 16582903
110 | #define IRCODE_ADAFRUIT_2 0x00FD8877 // 16615543
111 | #define IRCODE_ADAFRUIT_3 0x00FD48B7 // 16599223
112 | #define IRCODE_ADAFRUIT_4 0x00FD28D7 // 16591063
113 | #define IRCODE_ADAFRUIT_5 0x00FDA857 // 16623703
114 | #define IRCODE_ADAFRUIT_6 0x00FD6897 // 16607383
115 | #define IRCODE_ADAFRUIT_7 0x00FD18E7 // 16586983
116 | #define IRCODE_ADAFRUIT_8 0x00FD9867 // 16619623
117 | #define IRCODE_ADAFRUIT_9 0x00FD58A7 // 16603303
118 |
119 | // IR Raw Key Codes for eTopxizu 44Key IR Remote Controller for 5050 3528 RGB LED Light Strip
120 | #define IRCODE_ETOPXIZU_HELD 0x7FFFFFFF // 4294967295
121 | #define IRCODE_ETOPXIZU_POWER 16712445
122 | #define IRCODE_ETOPXIZU_PLAY_PAUSE 16745085
123 | #define IRCODE_ETOPXIZU_BRIGHTNESS_UP 16726725
124 | #define IRCODE_ETOPXIZU_BRIGHTNESS_DOWN 16759365
125 |
126 | #define IRCODE_ETOPXIZU_DIY1 16724175
127 | #define IRCODE_ETOPXIZU_DIY2 16756815
128 | #define IRCODE_ETOPXIZU_DIY3 16740495
129 | #define IRCODE_ETOPXIZU_DIY4 16716015
130 | #define IRCODE_ETOPXIZU_DIY5 16748655
131 | #define IRCODE_ETOPXIZU_DIY6 16732335
132 |
133 | #define IRCODE_ETOPXIZU_JUMP3 16720095
134 | #define IRCODE_ETOPXIZU_JUMP7 16752735
135 | #define IRCODE_ETOPXIZU_FADE3 16736415
136 | #define IRCODE_ETOPXIZU_FADE7 16769055
137 | #define IRCODE_ETOPXIZU_FLASH 16764975
138 | #define IRCODE_ETOPXIZU_AUTO 16773135
139 |
140 | #define IRCODE_ETOPXIZU_QUICK 16771095
141 | #define IRCODE_ETOPXIZU_SLOW 16762935
142 |
143 | #define IRCODE_ETOPXIZU_RED_UP 16722135
144 | #define IRCODE_ETOPXIZU_RED_DOWN 16713975
145 |
146 | #define IRCODE_ETOPXIZU_GREEN_UP 16754775
147 | #define IRCODE_ETOPXIZU_GREEN_DOWN 16746615
148 |
149 | #define IRCODE_ETOPXIZU_BLUE_UP 16738455
150 | #define IRCODE_ETOPXIZU_BLUE_DOWN 16730295
151 |
152 | #define IRCODE_ETOPXIZU_RED 16718565
153 | #define IRCODE_ETOPXIZU_RED_ORANGE 16722645
154 | #define IRCODE_ETOPXIZU_ORANGE 16714485
155 | #define IRCODE_ETOPXIZU_YELLOW_ORANGE 16726215
156 | #define IRCODE_ETOPXIZU_YELLOW 16718055
157 |
158 | #define IRCODE_ETOPXIZU_GREEN 16751205
159 | #define IRCODE_ETOPXIZU_LIME 16755285
160 | #define IRCODE_ETOPXIZU_AQUA 16747125
161 | #define IRCODE_ETOPXIZU_TEAL 16758855
162 | #define IRCODE_ETOPXIZU_NAVY 16750695
163 |
164 | #define IRCODE_ETOPXIZU_BLUE 16753245
165 | #define IRCODE_ETOPXIZU_ROYAL_BLUE 16749165
166 | #define IRCODE_ETOPXIZU_PURPLE 16757325
167 | #define IRCODE_ETOPXIZU_INDIGO 16742535
168 | #define IRCODE_ETOPXIZU_MAGENTA 16734375
169 |
170 | #define IRCODE_ETOPXIZU_WHITE 16720605
171 | #define IRCODE_ETOPXIZU_PINK 16716525
172 | #define IRCODE_ETOPXIZU_LIGHT_PINK 16724685
173 | #define IRCODE_ETOPXIZU_BABY_BLUE 16775175
174 | #define IRCODE_ETOPXIZU_LIGHT_BLUE 16767015
175 |
176 | bool sparkfunRemoteEnabled = false;
177 | bool adafruitRemoteEnabled = true;
178 | bool etopxizuRemoteEnabled = true;
179 |
180 | // Low level IR code reading function
181 | // Function will return 0 if no IR code available
182 | unsigned long decodeIRCode() {
183 |
184 | decode_results results;
185 |
186 | results.value = 0;
187 |
188 | // Attempt to read an IR code ?
189 | if (irReceiver.decode(&results)) {
190 | delay(20);
191 |
192 | if (results.value != 0)
193 | // Serial.println(results.value);
194 |
195 | // Prepare to receive the next IR code
196 | irReceiver.resume();
197 | }
198 |
199 | return results.value;
200 | }
201 |
202 | // Read an IR code
203 | // Function will return 0 if no IR code available
204 | unsigned long readIRCode() {
205 |
206 | // Is there an IR code to read ?
207 | unsigned long code = decodeIRCode();
208 | if (code == 0) {
209 | // No code so return 0
210 | return 0;
211 | }
212 |
213 | // Keep reading until code changes
214 | while (decodeIRCode() == code) {
215 | ;
216 | }
217 | // Serial.println(code);
218 | return code;
219 | }
220 |
221 | unsigned long lastIrCode = 0;
222 |
223 | unsigned int holdStartTime = 0;
224 | unsigned int defaultHoldDelay = 500;
225 | bool isHolding = false;
226 |
227 | unsigned int zeroStartTime = 0;
228 | unsigned int zeroDelay = 120;
229 |
230 | unsigned long readIRCode(unsigned int holdDelay) {
231 | // read the raw code from the sensor
232 | unsigned long irCode = readIRCode();
233 |
234 | //Serial.print(millis());
235 | //Serial.print("\t");
236 | //Serial.println(irCode);
237 |
238 | // don't return a short click until we know it's not a long hold
239 | // we'll have to wait for holdDelay ms to pass before returning a non-zero IR code
240 | // then, after that delay, as long as the button is held, we can keep returning the code
241 | // every time until it's released
242 |
243 | // the ir remote only sends codes every 107 ms or so (avg 106.875, max 111, min 102),
244 | // so the ir sensor will return 0 even if a button is held
245 | // so we have to wait longer than that before returning a non-zero code
246 | // in order to detect that a button has been released and is no longer held
247 |
248 | // only reset after we've gotten 0 back for more than the ir remote send interval
249 | unsigned int zeroTime = 0;
250 |
251 | if (irCode == 0) {
252 | zeroTime = millis() - zeroStartTime;
253 | if (zeroTime >= zeroDelay && lastIrCode != 0) {
254 | //Serial.println(F("zero delay has elapsed, returning last ir code"));
255 | // the button has been released for longer than the zero delay
256 | // start over delays over and return the last code
257 | irCode = lastIrCode;
258 | lastIrCode = 0;
259 | return irCode;
260 | }
261 |
262 | return 0;
263 | }
264 |
265 | // reset the zero timer every time a non-zero code is read
266 | zeroStartTime = millis();
267 |
268 | unsigned int heldTime = 0;
269 |
270 | if (irCode == IRCODE_SPARKFUN_HELD || irCode == IRCODE_ADAFRUIT_HELD) {
271 | // has the hold delay passed?
272 | heldTime = millis() - holdStartTime;
273 | if (heldTime >= holdDelay) {
274 | isHolding = true;
275 | //Serial.println(F("hold delay has elapsed, returning last ir code"));
276 | return lastIrCode;
277 | }
278 | else if (holdStartTime == 0) {
279 | isHolding = false;
280 | holdStartTime = millis();
281 | }
282 | }
283 | else {
284 | // not zero, not IRCODE_SPARKFUN_HELD
285 | // store it for use later, until the hold and zero delays have elapsed
286 | holdStartTime = millis();
287 | isHolding = false;
288 | lastIrCode = irCode;
289 | return 0;
290 | }
291 |
292 | return 0;
293 | }
294 |
295 | void heldButtonHasBeenHandled() {
296 | lastIrCode = 0;
297 | isHolding = false;
298 | holdStartTime = 0;
299 | }
300 |
301 | unsigned long waitForIRCode() {
302 |
303 | unsigned long irCode = readIRCode();
304 | while ((irCode == 0) || (irCode == 0xFFFFFFFF)) {
305 | delay(200);
306 | irCode = readIRCode();
307 | }
308 | return irCode;
309 | }
310 |
311 | InputCommand getCommand(unsigned long input) {
312 | if (adafruitRemoteEnabled) {
313 | switch (input) {
314 | case IRCODE_ADAFRUIT_UP:
315 | return InputCommand::Up;
316 |
317 | case IRCODE_ADAFRUIT_DOWN:
318 | return InputCommand::Down;
319 |
320 | case IRCODE_ADAFRUIT_LEFT:
321 | return InputCommand::Left;
322 |
323 | case IRCODE_ADAFRUIT_RIGHT:
324 | return InputCommand::Right;
325 |
326 | case IRCODE_ADAFRUIT_ENTER_SAVE:
327 | return InputCommand::Select;
328 |
329 | case IRCODE_ADAFRUIT_STOP_MODE:
330 | case IRCODE_ADAFRUIT_1:
331 | return InputCommand::PlayMode;
332 |
333 | case IRCODE_ADAFRUIT_2:
334 | return InputCommand::CyclePalette;
335 |
336 | case IRCODE_ADAFRUIT_PLAY_PAUSE:
337 | return InputCommand::Power;
338 |
339 | case IRCODE_ADAFRUIT_VOLUME_UP:
340 | return InputCommand::BrightnessUp;
341 |
342 | case IRCODE_ADAFRUIT_VOLUME_DOWN:
343 | return InputCommand::BrightnessDown;
344 | }
345 | }
346 |
347 | if (sparkfunRemoteEnabled) {
348 | switch (input) {
349 | case IRCODE_SPARKFUN_UP:
350 | return InputCommand::Up;
351 |
352 | case IRCODE_SPARKFUN_DOWN:
353 | return InputCommand::Down;
354 |
355 | case IRCODE_SPARKFUN_LEFT:
356 | return InputCommand::Left;
357 |
358 | case IRCODE_SPARKFUN_RIGHT:
359 | return InputCommand::Right;
360 |
361 | case IRCODE_SPARKFUN_SELECT:
362 | return InputCommand::Select;
363 |
364 | case IRCODE_SPARKFUN_POWER:
365 | return InputCommand::Brightness;
366 |
367 | case IRCODE_SPARKFUN_A:
368 | return InputCommand::PlayMode;
369 |
370 | case IRCODE_SPARKFUN_B:
371 | return InputCommand::CyclePalette;
372 | }
373 | }
374 |
375 | if (etopxizuRemoteEnabled) {
376 | switch (input) {
377 | case IRCODE_ETOPXIZU_QUICK:
378 | return InputCommand::Up;
379 |
380 | case IRCODE_ETOPXIZU_SLOW:
381 | return InputCommand::Down;
382 |
383 | case IRCODE_ETOPXIZU_PLAY_PAUSE:
384 | return InputCommand::PlayMode;
385 |
386 | case IRCODE_ETOPXIZU_POWER:
387 | return InputCommand::Power;
388 |
389 | case IRCODE_ETOPXIZU_BRIGHTNESS_UP:
390 | return InputCommand::BrightnessUp;
391 | case IRCODE_ETOPXIZU_BRIGHTNESS_DOWN:
392 | return InputCommand::BrightnessDown;
393 |
394 | case IRCODE_ETOPXIZU_DIY1:
395 | return InputCommand::Pattern1;
396 | case IRCODE_ETOPXIZU_DIY2:
397 | return InputCommand::Pattern2;
398 | case IRCODE_ETOPXIZU_DIY3:
399 | return InputCommand::Pattern3;
400 | case IRCODE_ETOPXIZU_DIY4:
401 | return InputCommand::Pattern4;
402 | case IRCODE_ETOPXIZU_DIY5:
403 | return InputCommand::Pattern5;
404 | case IRCODE_ETOPXIZU_DIY6:
405 | return InputCommand::Pattern6;
406 | case IRCODE_ETOPXIZU_JUMP3:
407 | return InputCommand::Pattern7;
408 | case IRCODE_ETOPXIZU_JUMP7:
409 | return InputCommand::Pattern8;
410 | case IRCODE_ETOPXIZU_FADE3:
411 | return InputCommand::Pattern9;
412 | case IRCODE_ETOPXIZU_FADE7:
413 | return InputCommand::Pattern10;
414 |
415 | case IRCODE_ETOPXIZU_FLASH:
416 | return InputCommand::PreviousPalette;
417 | // return InputCommand::Pattern11;
418 |
419 | case IRCODE_ETOPXIZU_AUTO:
420 | return InputCommand::NextPalette;
421 | // return InputCommand::Pattern12;
422 |
423 | case IRCODE_ETOPXIZU_RED_UP:
424 | return InputCommand::RedUp;
425 | case IRCODE_ETOPXIZU_RED_DOWN:
426 | return InputCommand::RedDown;
427 |
428 | case IRCODE_ETOPXIZU_GREEN_UP:
429 | return InputCommand::GreenUp;
430 | case IRCODE_ETOPXIZU_GREEN_DOWN:
431 | return InputCommand::GreenDown;
432 |
433 | case IRCODE_ETOPXIZU_BLUE_UP:
434 | return InputCommand::BlueUp;
435 | case IRCODE_ETOPXIZU_BLUE_DOWN:
436 | return InputCommand::BlueDown;
437 |
438 | case IRCODE_ETOPXIZU_RED:
439 | return InputCommand::Red;
440 | case IRCODE_ETOPXIZU_RED_ORANGE:
441 | return InputCommand::RedOrange;
442 | case IRCODE_ETOPXIZU_ORANGE:
443 | return InputCommand::Orange;
444 | case IRCODE_ETOPXIZU_YELLOW_ORANGE:
445 | return InputCommand::YellowOrange;
446 | case IRCODE_ETOPXIZU_YELLOW:
447 | return InputCommand::Yellow;
448 |
449 | case IRCODE_ETOPXIZU_GREEN:
450 | return InputCommand::Green;
451 | case IRCODE_ETOPXIZU_LIME:
452 | return InputCommand::Lime;
453 | case IRCODE_ETOPXIZU_AQUA:
454 | return InputCommand::Aqua;
455 | case IRCODE_ETOPXIZU_TEAL:
456 | return InputCommand::Teal;
457 | case IRCODE_ETOPXIZU_NAVY:
458 | return InputCommand::Navy;
459 |
460 | case IRCODE_ETOPXIZU_BLUE:
461 | return InputCommand::Blue;
462 | case IRCODE_ETOPXIZU_ROYAL_BLUE:
463 | return InputCommand::RoyalBlue;
464 | case IRCODE_ETOPXIZU_PURPLE:
465 | return InputCommand::Purple;
466 | case IRCODE_ETOPXIZU_INDIGO:
467 | return InputCommand::Indigo;
468 | case IRCODE_ETOPXIZU_MAGENTA:
469 | return InputCommand::Magenta;
470 |
471 | case IRCODE_ETOPXIZU_WHITE:
472 | return InputCommand::White;
473 | case IRCODE_ETOPXIZU_PINK:
474 | return InputCommand::Pink;
475 | case IRCODE_ETOPXIZU_LIGHT_PINK:
476 | return InputCommand::LightPink;
477 | case IRCODE_ETOPXIZU_BABY_BLUE:
478 | return InputCommand::BabyBlue;
479 | case IRCODE_ETOPXIZU_LIGHT_BLUE:
480 | return InputCommand::LightBlue;
481 | }
482 | }
483 |
484 | return InputCommand::None;
485 | }
486 |
487 | InputCommand readCommand() {
488 | return getCommand(readIRCode());
489 | }
490 |
491 | InputCommand readCommand(unsigned int holdDelay) {
492 | return getCommand(readIRCode(holdDelay));
493 | }
494 |
495 | #endif
496 |
--------------------------------------------------------------------------------
/Drawing.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Torch: https://github.com/evilgeniuslabs/torch
3 | * Copyright (C) 2015 Jason Coon
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | void drawCircle(int16_t x0, int16_t y0, uint16_t radius, const CRGB& color)
20 | {
21 | int a = radius, b = 0;
22 | int radiusError = 1 - a;
23 |
24 | if (radius == 0) {
25 | leds[XY(x0, y0)] = color;
26 | return;
27 | }
28 |
29 | while (a >= b)
30 | {
31 | leds[XY(a + x0, b + y0)] = color;
32 | leds[XY(b + x0, a + y0)] = color;
33 | leds[XY(-a + x0, b + y0)] = color;
34 | leds[XY(-b + x0, a + y0)] = color;
35 | leds[XY(-a + x0, -b + y0)] = color;
36 | leds[XY(-b + x0, -a + y0)] = color;
37 | leds[XY(a + x0, -b + y0)] = color;
38 | leds[XY(b + x0, -a + y0)] = color;
39 |
40 | b++;
41 | if (radiusError < 0)
42 | radiusError += 2 * b + 1;
43 | else
44 | {
45 | a--;
46 | radiusError += 2 * (b - a + 1);
47 | }
48 | }
49 | }
50 |
51 | void drawFastVLine(uint16_t x, uint16_t y0, uint16_t y1, const CRGB& color) {
52 | uint16_t i;
53 |
54 | for (i = y0; i <= y1; i++) {
55 | leds[XY(x, i)] = color;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Effects.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Torch: https://github.com/evilgeniuslabs/torch
3 | * Copyright (C) 2015 Jason Coon
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | // give it a linear tail to the right
20 | void streamRight(byte scale, int fromX = 0, int toX = MATRIX_WIDTH, int fromY = 0, int toY = MATRIX_HEIGHT)
21 | {
22 | for (int x = fromX + 1; x < toX; x++) {
23 | for (int y = fromY; y < toY; y++) {
24 | leds[XY(x, y)] += leds[XY(x - 1, y)];
25 | leds[XY(x, y)].nscale8(scale);
26 | }
27 | }
28 | for (int y = fromY; y < toY; y++)
29 | leds[XY(0, y)].nscale8(scale);
30 | }
31 |
32 | // give it a linear tail to the left
33 | void streamLeft(byte scale, int fromX = MATRIX_WIDTH, int toX = 0, int fromY = 0, int toY = MATRIX_HEIGHT)
34 | {
35 | for (int x = toX; x < fromX; x++) {
36 | for (int y = fromY; y < toY; y++) {
37 | leds[XY(x, y)] += leds[XY(x + 1, y)];
38 | leds[XY(x, y)].nscale8(scale);
39 | }
40 | }
41 | for (int y = fromY; y < toY; y++)
42 | leds[XY(0, y)].nscale8(scale);
43 | }
44 |
45 | // give it a linear tail downwards
46 | void streamDown(byte scale)
47 | {
48 | for (int x = 0; x < MATRIX_WIDTH; x++) {
49 | for (int y = 1; y < MATRIX_HEIGHT; y++) {
50 | leds[XY(x, y)] += leds[XY(x, y - 1)];
51 | leds[XY(x, y)].nscale8(scale);
52 | }
53 | }
54 | for (int x = 0; x < MATRIX_WIDTH; x++)
55 | leds[XY(x, 0)].nscale8(scale);
56 | }
57 |
58 | // give it a linear tail upwards
59 | void streamUp(byte scale)
60 | {
61 | for (int x = 0; x < MATRIX_WIDTH; x++) {
62 | for (int y = MATRIX_HEIGHT - 2; y >= 0; y--) {
63 | leds[XY(x, y)] += leds[XY(x, y + 1)];
64 | leds[XY(x, y)].nscale8(scale);
65 | }
66 | }
67 | for (int x = 0; x < MATRIX_WIDTH; x++)
68 | leds[XY(x, MATRIX_HEIGHT - 1)].nscale8(scale);
69 | }
70 |
71 | // give it a linear tail up and to the left
72 | void streamUpAndLeft(byte scale)
73 | {
74 | for (int x = 0; x < MATRIX_WIDTH - 1; x++) {
75 | for (int y = MATRIX_HEIGHT - 2; y >= 0; y--) {
76 | leds[XY(x, y)] += leds[XY(x + 1, y + 1)];
77 | leds[XY(x, y)].nscale8(scale);
78 | }
79 | }
80 | for (int x = 0; x < MATRIX_WIDTH; x++)
81 | leds[XY(x, MATRIX_HEIGHT - 1)].nscale8(scale);
82 | for (int y = 0; y < MATRIX_HEIGHT; y++)
83 | leds[XY(MATRIX_WIDTH - 1, y)].nscale8(scale);
84 | }
85 |
86 | // give it a linear tail up and to the right
87 | void streamUpAndRight(byte scale)
88 | {
89 | for (int x = 0; x < MATRIX_WIDTH - 1; x++) {
90 | for (int y = MATRIX_HEIGHT - 2; y >= 0; y--) {
91 | leds[XY(x + 1, y)] += leds[XY(x, y + 1)];
92 | leds[XY(x, y)].nscale8(scale);
93 | }
94 | }
95 | // fade the bottom row
96 | for (int x = 0; x < MATRIX_WIDTH; x++)
97 | leds[XY(x, MATRIX_HEIGHT - 1)].nscale8(scale);
98 |
99 | // fade the right column
100 | for (int y = 0; y < MATRIX_HEIGHT; y++)
101 | leds[XY(MATRIX_WIDTH - 1, y)].nscale8(scale);
102 | }
103 |
104 | void moveUp()
105 | {
106 | for (int y = 0; y < MATRIX_HEIGHT - 1; y++) {
107 | for (int x = 0; x < MATRIX_WIDTH; x++) {
108 | leds[XY(x, y)] = leds[XY(x, y + 1)];
109 | }
110 | }
111 | }
112 |
113 | void moveDown() {
114 | for (int y = MATRIX_HEIGHT - 1; y > 0; y--) {
115 | for (int x = 0; x < MATRIX_WIDTH; x++) {
116 | leds[XY(x, y)] = leds[XY(x, y - 1)];
117 | }
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/Fire2012WithPalette.h:
--------------------------------------------------------------------------------
1 | // Fire2012 with programmable Color Palette
2 | // by Mark Kriegsman: https://github.com/FastLED/FastLED/blob/master/examples/Fire2012WithPalette/Fire2012WithPalette.ino
3 | //
4 | // This code is the same fire simulation as the original "Fire2012",
5 | // but each heat cell's temperature is translated to color through a FastLED
6 | // programmable color palette, instead of through the "HeatColor(...)" function.
7 | //
8 | // Four different static color palettes are provided here, plus one dynamic one.
9 | //
10 | // The three static ones are:
11 | // 1. the FastLED built-in HeatColors_p -- this is the default, and it looks
12 | // pretty much exactly like the original Fire2012.
13 | //
14 | // To use any of the other palettes below, just "uncomment" the corresponding code.
15 | //
16 | // 2. a gradient from black to red to yellow to white, which is
17 | // visually similar to the HeatColors_p, and helps to illustrate
18 | // what the 'heat colors' palette is actually doing,
19 | // 3. a similar gradient, but in blue colors rather than red ones,
20 | // i.e. from black to blue to aqua to white, which results in
21 | // an "icy blue" fire effect,
22 | // 4. a simplified three-step gradient, from black to red to white, just to show
23 | // that these gradients need not have four components; two or
24 | // three are possible, too, even if they don't look quite as nice for fire.
25 | //
26 | // The dynamic palette shows how you can change the basic 'hue' of the
27 | // color palette every time through the loop, producing "rainbow fire".
28 |
29 | // Fire2012 by Mark Kriegsman, July 2012
30 | // as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY
31 | ////
32 | // This basic one-dimensional 'fire' simulation works roughly as follows:
33 | // There's a underlying array of 'heat' cells, that model the temperature
34 | // at each point along the line. Every cycle through the simulation,
35 | // four steps are performed:
36 | // 1) All cells cool down a little bit, losing heat to the air
37 | // 2) The heat from each cell drifts 'up' and diffuses a little
38 | // 3) Sometimes randomly new 'sparks' of heat are added at the bottom
39 | // 4) The heat from each cell is rendered as a color into the leds array
40 | // The heat-to-color mapping uses a black-body radiation approximation.
41 | //
42 | // Temperature is in arbitrary units from 0 (cold black) to 255 (white hot).
43 | //
44 | // This simulation scales it self a bit depending on MATRIX_HEIGHT; it should look
45 | // "OK" on anywhere from 20 to 100 LEDs without too much tweaking.
46 | //
47 | // I recommend running this simulation at anywhere from 30-100 frames per second,
48 | // meaning an interframe delay of about 10-35 milliseconds.
49 | //
50 | // Looks best on a high-density LED setup (60+ pixels/meter).
51 | //
52 | //
53 | // There are two main parameters you can play with to control the look and
54 | // feel of your fire: COOLING (used in step 1 above), and SPARKING (used
55 | // in step 3 above).
56 | //
57 | // COOLING: How much does the air cool as it rises?
58 | // Less cooling = taller flames. More cooling = shorter flames.
59 | // Default 55, suggested range 20-100
60 | #define COOLING 55 // 100 // 55 // 86
61 |
62 | // SPARKING: What chance (out of 255) is there that a new spark will be lit?
63 | // Higher chance = more roaring fire. Lower chance = more flickery fire.
64 | // Default 120, suggested range 50-200.
65 | #define SPARKING 50 // 30 // 120 // 90 // 60
66 |
67 | uint16_t fire2012WithPalette()
68 | {
69 | // Array of temperature readings at each simulation cell
70 | static byte heat[MATRIX_WIDTH][MATRIX_HEIGHT];
71 |
72 | for(uint8_t x = 0; x < MATRIX_WIDTH; x++) {
73 | // Step 1. Cool down every cell a little
74 | for (int i = 0; i < MATRIX_HEIGHT; i++) {
75 | heat[x][i] = qsub8(heat[x][i], random8(0, ((COOLING * 10) / MATRIX_HEIGHT) + 2));
76 | }
77 |
78 | // Step 2. Heat from each cell drifts 'up' and diffuses a little
79 | for (int k = MATRIX_HEIGHT - 1; k >= 2; k--) {
80 | heat[x][k] = (heat[x][k - 1] + heat[x][k - 2] + heat[x][k - 2]) / 3;
81 | }
82 |
83 | // Step 3. Randomly ignite new 'sparks' of heat near the bottom
84 | if (random8() < SPARKING) {
85 | int y = random8(2);
86 | heat[x][y] = qadd8(heat[x][y], random8(160, 255));
87 | }
88 |
89 | // Step 4. Map from heat cells to LED colors
90 | for (int j = 0; j < MATRIX_HEIGHT; j++) {
91 | // Scale the heat value from 0-255 down to 0-240
92 | // for best results with color palettes.
93 | byte colorindex = scale8(heat[x][j], 240);
94 | leds[XY(x, (MATRIX_HEIGHT - 1) - j)] = ColorFromPalette(HeatColors_p, colorindex);
95 | }
96 | }
97 |
98 | return 15;
99 | }
100 |
--------------------------------------------------------------------------------
/GradientPalettes.h:
--------------------------------------------------------------------------------
1 | // ColorWavesWithPalettes
2 | // Animated shifting color waves, with several cross-fading color palettes.
3 | // by Mark Kriegsman, August 2015
4 | //
5 | // Color palettes courtesy of cpt-city and its contributors:
6 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/
7 | //
8 | // Color palettes converted for FastLED using "PaletteKnife" v1:
9 | // http://fastled.io/tools/paletteknife/
10 | //
11 |
12 | // Gradient Color Palette definitions for 33 different cpt-city color palettes.
13 | // 956 bytes of PROGMEM for all of the palettes together,
14 | // +618 bytes of PROGMEM for gradient palette code (AVR).
15 | // 1,494 bytes total for all 34 color palettes and associated code.
16 |
17 | // Gradient palette "ib_jul01_gp", originally from
18 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/ing/xmas/tn/ib_jul01.png.index.html
19 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
20 | // Size: 16 bytes of program space.
21 |
22 | DEFINE_GRADIENT_PALETTE( ib_jul01_gp ) {
23 | 0, 194, 1, 1,
24 | 94, 1, 29, 18,
25 | 132, 57,131, 28,
26 | 255, 113, 1, 1};
27 |
28 | // Gradient palette "es_vintage_57_gp", originally from
29 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/vintage/tn/es_vintage_57.png.index.html
30 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
31 | // Size: 20 bytes of program space.
32 |
33 | DEFINE_GRADIENT_PALETTE( es_vintage_57_gp ) {
34 | 0, 2, 1, 1,
35 | 53, 18, 1, 0,
36 | 104, 69, 29, 1,
37 | 153, 167,135, 10,
38 | 255, 46, 56, 4};
39 |
40 | // Gradient palette "es_vintage_01_gp", originally from
41 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/vintage/tn/es_vintage_01.png.index.html
42 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
43 | // Size: 32 bytes of program space.
44 |
45 | DEFINE_GRADIENT_PALETTE( es_vintage_01_gp ) {
46 | 0, 4, 1, 1,
47 | 51, 16, 0, 1,
48 | 76, 97,104, 3,
49 | 101, 255,131, 19,
50 | 127, 67, 9, 4,
51 | 153, 16, 0, 1,
52 | 229, 4, 1, 1,
53 | 255, 4, 1, 1};
54 |
55 | // Gradient palette "es_rivendell_15_gp", originally from
56 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/rivendell/tn/es_rivendell_15.png.index.html
57 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
58 | // Size: 20 bytes of program space.
59 |
60 | DEFINE_GRADIENT_PALETTE( es_rivendell_15_gp ) {
61 | 0, 1, 14, 5,
62 | 101, 16, 36, 14,
63 | 165, 56, 68, 30,
64 | 242, 150,156, 99,
65 | 255, 150,156, 99};
66 |
67 | // Gradient palette "rgi_15_gp", originally from
68 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/ds/rgi/tn/rgi_15.png.index.html
69 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
70 | // Size: 36 bytes of program space.
71 |
72 | DEFINE_GRADIENT_PALETTE( rgi_15_gp ) {
73 | 0, 4, 1, 31,
74 | 31, 55, 1, 16,
75 | 63, 197, 3, 7,
76 | 95, 59, 2, 17,
77 | 127, 6, 2, 34,
78 | 159, 39, 6, 33,
79 | 191, 112, 13, 32,
80 | 223, 56, 9, 35,
81 | 255, 22, 6, 38};
82 |
83 | // Gradient palette "retro2_16_gp", originally from
84 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/ma/retro2/tn/retro2_16.png.index.html
85 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
86 | // Size: 8 bytes of program space.
87 |
88 | DEFINE_GRADIENT_PALETTE( retro2_16_gp ) {
89 | 0, 188,135, 1,
90 | 255, 46, 7, 1};
91 |
92 | // Gradient palette "Analogous_1_gp", originally from
93 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/red/tn/Analogous_1.png.index.html
94 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
95 | // Size: 20 bytes of program space.
96 |
97 | DEFINE_GRADIENT_PALETTE( Analogous_1_gp ) {
98 | 0, 3, 0,255,
99 | 63, 23, 0,255,
100 | 127, 67, 0,255,
101 | 191, 142, 0, 45,
102 | 255, 255, 0, 0};
103 |
104 | // Gradient palette "es_pinksplash_08_gp", originally from
105 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/pink_splash/tn/es_pinksplash_08.png.index.html
106 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
107 | // Size: 20 bytes of program space.
108 |
109 | DEFINE_GRADIENT_PALETTE( es_pinksplash_08_gp ) {
110 | 0, 126, 11,255,
111 | 127, 197, 1, 22,
112 | 175, 210,157,172,
113 | 221, 157, 3,112,
114 | 255, 157, 3,112};
115 |
116 | // Gradient palette "es_pinksplash_07_gp", originally from
117 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/pink_splash/tn/es_pinksplash_07.png.index.html
118 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
119 | // Size: 28 bytes of program space.
120 |
121 | DEFINE_GRADIENT_PALETTE( es_pinksplash_07_gp ) {
122 | 0, 229, 1, 1,
123 | 61, 242, 4, 63,
124 | 101, 255, 12,255,
125 | 127, 249, 81,252,
126 | 153, 255, 11,235,
127 | 193, 244, 5, 68,
128 | 255, 232, 1, 5};
129 |
130 | // Gradient palette "Coral_reef_gp", originally from
131 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/other/tn/Coral_reef.png.index.html
132 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
133 | // Size: 24 bytes of program space.
134 |
135 | DEFINE_GRADIENT_PALETTE( Coral_reef_gp ) {
136 | 0, 40,199,197,
137 | 50, 10,152,155,
138 | 96, 1,111,120,
139 | 96, 43,127,162,
140 | 139, 10, 73,111,
141 | 255, 1, 34, 71};
142 |
143 | // Gradient palette "es_ocean_breeze_068_gp", originally from
144 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/ocean_breeze/tn/es_ocean_breeze_068.png.index.html
145 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
146 | // Size: 24 bytes of program space.
147 |
148 | DEFINE_GRADIENT_PALETTE( es_ocean_breeze_068_gp ) {
149 | 0, 100,156,153,
150 | 51, 1, 99,137,
151 | 101, 1, 68, 84,
152 | 104, 35,142,168,
153 | 178, 0, 63,117,
154 | 255, 1, 10, 10};
155 |
156 | // Gradient palette "es_ocean_breeze_036_gp", originally from
157 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/ocean_breeze/tn/es_ocean_breeze_036.png.index.html
158 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
159 | // Size: 16 bytes of program space.
160 |
161 | DEFINE_GRADIENT_PALETTE( es_ocean_breeze_036_gp ) {
162 | 0, 1, 6, 7,
163 | 89, 1, 99,111,
164 | 153, 144,209,255,
165 | 255, 0, 73, 82};
166 |
167 | // Gradient palette "departure_gp", originally from
168 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/mjf/tn/departure.png.index.html
169 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
170 | // Size: 88 bytes of program space.
171 |
172 | DEFINE_GRADIENT_PALETTE( departure_gp ) {
173 | 0, 8, 3, 0,
174 | 42, 23, 7, 0,
175 | 63, 75, 38, 6,
176 | 84, 169, 99, 38,
177 | 106, 213,169,119,
178 | 116, 255,255,255,
179 | 138, 135,255,138,
180 | 148, 22,255, 24,
181 | 170, 0,255, 0,
182 | 191, 0,136, 0,
183 | 212, 0, 55, 0,
184 | 255, 0, 55, 0};
185 |
186 | // Gradient palette "es_landscape_64_gp", originally from
187 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/landscape/tn/es_landscape_64.png.index.html
188 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
189 | // Size: 36 bytes of program space.
190 |
191 | DEFINE_GRADIENT_PALETTE( es_landscape_64_gp ) {
192 | 0, 0, 0, 0,
193 | 37, 2, 25, 1,
194 | 76, 15,115, 5,
195 | 127, 79,213, 1,
196 | 128, 126,211, 47,
197 | 130, 188,209,247,
198 | 153, 144,182,205,
199 | 204, 59,117,250,
200 | 255, 1, 37,192};
201 |
202 | // Gradient palette "es_landscape_33_gp", originally from
203 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/landscape/tn/es_landscape_33.png.index.html
204 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
205 | // Size: 24 bytes of program space.
206 |
207 | DEFINE_GRADIENT_PALETTE( es_landscape_33_gp ) {
208 | 0, 1, 5, 0,
209 | 19, 32, 23, 1,
210 | 38, 161, 55, 1,
211 | 63, 229,144, 1,
212 | 66, 39,142, 74,
213 | 255, 1, 4, 1};
214 |
215 | // Gradient palette "rainbowsherbet_gp", originally from
216 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/ma/icecream/tn/rainbowsherbet.png.index.html
217 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
218 | // Size: 28 bytes of program space.
219 |
220 | DEFINE_GRADIENT_PALETTE( rainbowsherbet_gp ) {
221 | 0, 255, 33, 4,
222 | 43, 255, 68, 25,
223 | 86, 255, 7, 25,
224 | 127, 255, 82,103,
225 | 170, 255,255,242,
226 | 209, 42,255, 22,
227 | 255, 87,255, 65};
228 |
229 | // Gradient palette "gr65_hult_gp", originally from
230 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/hult/tn/gr65_hult.png.index.html
231 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
232 | // Size: 24 bytes of program space.
233 |
234 | DEFINE_GRADIENT_PALETTE( gr65_hult_gp ) {
235 | 0, 247,176,247,
236 | 48, 255,136,255,
237 | 89, 220, 29,226,
238 | 160, 7, 82,178,
239 | 216, 1,124,109,
240 | 255, 1,124,109};
241 |
242 | // Gradient palette "gr64_hult_gp", originally from
243 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/hult/tn/gr64_hult.png.index.html
244 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
245 | // Size: 32 bytes of program space.
246 |
247 | DEFINE_GRADIENT_PALETTE( gr64_hult_gp ) {
248 | 0, 1,124,109,
249 | 66, 1, 93, 79,
250 | 104, 52, 65, 1,
251 | 130, 115,127, 1,
252 | 150, 52, 65, 1,
253 | 201, 1, 86, 72,
254 | 239, 0, 55, 45,
255 | 255, 0, 55, 45};
256 |
257 | // Gradient palette "GMT_drywet_gp", originally from
258 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/gmt/tn/GMT_drywet.png.index.html
259 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
260 | // Size: 28 bytes of program space.
261 |
262 | DEFINE_GRADIENT_PALETTE( GMT_drywet_gp ) {
263 | 0, 47, 30, 2,
264 | 42, 213,147, 24,
265 | 84, 103,219, 52,
266 | 127, 3,219,207,
267 | 170, 1, 48,214,
268 | 212, 1, 1,111,
269 | 255, 1, 7, 33};
270 |
271 | // Gradient palette "ib15_gp", originally from
272 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/ing/general/tn/ib15.png.index.html
273 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
274 | // Size: 24 bytes of program space.
275 |
276 | DEFINE_GRADIENT_PALETTE( ib15_gp ) {
277 | 0, 113, 91,147,
278 | 72, 157, 88, 78,
279 | 89, 208, 85, 33,
280 | 107, 255, 29, 11,
281 | 141, 137, 31, 39,
282 | 255, 59, 33, 89};
283 |
284 | // Gradient palette "Fuschia_7_gp", originally from
285 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/ds/fuschia/tn/Fuschia-7.png.index.html
286 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
287 | // Size: 20 bytes of program space.
288 |
289 | DEFINE_GRADIENT_PALETTE( Fuschia_7_gp ) {
290 | 0, 43, 3,153,
291 | 63, 100, 4,103,
292 | 127, 188, 5, 66,
293 | 191, 161, 11,115,
294 | 255, 135, 20,182};
295 |
296 | // Gradient palette "es_emerald_dragon_08_gp", originally from
297 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/emerald_dragon/tn/es_emerald_dragon_08.png.index.html
298 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
299 | // Size: 16 bytes of program space.
300 |
301 | DEFINE_GRADIENT_PALETTE( es_emerald_dragon_08_gp ) {
302 | 0, 97,255, 1,
303 | 101, 47,133, 1,
304 | 178, 13, 43, 1,
305 | 255, 2, 10, 1};
306 |
307 | // Gradient palette "lava_gp", originally from
308 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/neota/elem/tn/lava.png.index.html
309 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
310 | // Size: 52 bytes of program space.
311 |
312 | DEFINE_GRADIENT_PALETTE( lava_gp ) {
313 | 0, 0, 0, 0,
314 | 46, 18, 0, 0,
315 | 96, 113, 0, 0,
316 | 108, 142, 3, 1,
317 | 119, 175, 17, 1,
318 | 146, 213, 44, 2,
319 | 174, 255, 82, 4,
320 | 188, 255,115, 4,
321 | 202, 255,156, 4,
322 | 218, 255,203, 4,
323 | 234, 255,255, 4,
324 | 244, 255,255, 71,
325 | 255, 255,255,255};
326 |
327 | // Gradient palette "fire_gp", originally from
328 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/neota/elem/tn/fire.png.index.html
329 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
330 | // Size: 28 bytes of program space.
331 |
332 | DEFINE_GRADIENT_PALETTE( fire_gp ) {
333 | 0, 1, 1, 0,
334 | 76, 32, 5, 0,
335 | 146, 192, 24, 0,
336 | 197, 220,105, 5,
337 | 240, 252,255, 31,
338 | 250, 252,255,111,
339 | 255, 255,255,255};
340 |
341 | // Gradient palette "Colorfull_gp", originally from
342 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/atmospheric/tn/Colorfull.png.index.html
343 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
344 | // Size: 44 bytes of program space.
345 |
346 | DEFINE_GRADIENT_PALETTE( Colorfull_gp ) {
347 | 0, 10, 85, 5,
348 | 25, 29,109, 18,
349 | 60, 59,138, 42,
350 | 93, 83, 99, 52,
351 | 106, 110, 66, 64,
352 | 109, 123, 49, 65,
353 | 113, 139, 35, 66,
354 | 116, 192,117, 98,
355 | 124, 255,255,137,
356 | 168, 100,180,155,
357 | 255, 22,121,174};
358 |
359 | // Gradient palette "Magenta_Evening_gp", originally from
360 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/atmospheric/tn/Magenta_Evening.png.index.html
361 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
362 | // Size: 28 bytes of program space.
363 |
364 | DEFINE_GRADIENT_PALETTE( Magenta_Evening_gp ) {
365 | 0, 71, 27, 39,
366 | 31, 130, 11, 51,
367 | 63, 213, 2, 64,
368 | 70, 232, 1, 66,
369 | 76, 252, 1, 69,
370 | 108, 123, 2, 51,
371 | 255, 46, 9, 35};
372 |
373 | // Gradient palette "Pink_Purple_gp", originally from
374 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/atmospheric/tn/Pink_Purple.png.index.html
375 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
376 | // Size: 44 bytes of program space.
377 |
378 | DEFINE_GRADIENT_PALETTE( Pink_Purple_gp ) {
379 | 0, 19, 2, 39,
380 | 25, 26, 4, 45,
381 | 51, 33, 6, 52,
382 | 76, 68, 62,125,
383 | 102, 118,187,240,
384 | 109, 163,215,247,
385 | 114, 217,244,255,
386 | 122, 159,149,221,
387 | 149, 113, 78,188,
388 | 183, 128, 57,155,
389 | 255, 146, 40,123};
390 |
391 | // Gradient palette "Sunset_Real_gp", originally from
392 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/atmospheric/tn/Sunset_Real.png.index.html
393 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
394 | // Size: 28 bytes of program space.
395 |
396 | DEFINE_GRADIENT_PALETTE( Sunset_Real_gp ) {
397 | 0, 120, 0, 0,
398 | 22, 179, 22, 0,
399 | 51, 255,104, 0,
400 | 85, 167, 22, 18,
401 | 135, 100, 0,103,
402 | 198, 16, 0,130,
403 | 255, 0, 0,160};
404 |
405 | // Gradient palette "es_autumn_19_gp", originally from
406 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/autumn/tn/es_autumn_19.png.index.html
407 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
408 | // Size: 52 bytes of program space.
409 |
410 | DEFINE_GRADIENT_PALETTE( es_autumn_19_gp ) {
411 | 0, 26, 1, 1,
412 | 51, 67, 4, 1,
413 | 84, 118, 14, 1,
414 | 104, 137,152, 52,
415 | 112, 113, 65, 1,
416 | 122, 133,149, 59,
417 | 124, 137,152, 52,
418 | 135, 113, 65, 1,
419 | 142, 139,154, 46,
420 | 163, 113, 13, 1,
421 | 204, 55, 3, 1,
422 | 249, 17, 1, 1,
423 | 255, 17, 1, 1};
424 |
425 | // Gradient palette "BlacK_Blue_Magenta_White_gp", originally from
426 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/basic/tn/BlacK_Blue_Magenta_White.png.index.html
427 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
428 | // Size: 28 bytes of program space.
429 |
430 | DEFINE_GRADIENT_PALETTE( BlacK_Blue_Magenta_White_gp ) {
431 | 0, 0, 0, 0,
432 | 42, 0, 0, 45,
433 | 84, 0, 0,255,
434 | 127, 42, 0,255,
435 | 170, 255, 0,255,
436 | 212, 255, 55,255,
437 | 255, 255,255,255};
438 |
439 | // Gradient palette "BlacK_Magenta_Red_gp", originally from
440 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/basic/tn/BlacK_Magenta_Red.png.index.html
441 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
442 | // Size: 20 bytes of program space.
443 |
444 | DEFINE_GRADIENT_PALETTE( BlacK_Magenta_Red_gp ) {
445 | 0, 0, 0, 0,
446 | 63, 42, 0, 45,
447 | 127, 255, 0,255,
448 | 191, 255, 0, 45,
449 | 255, 255, 0, 0};
450 |
451 | // Gradient palette "BlacK_Red_Magenta_Yellow_gp", originally from
452 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/basic/tn/BlacK_Red_Magenta_Yellow.png.index.html
453 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
454 | // Size: 28 bytes of program space.
455 |
456 | DEFINE_GRADIENT_PALETTE( BlacK_Red_Magenta_Yellow_gp ) {
457 | 0, 0, 0, 0,
458 | 42, 42, 0, 0,
459 | 84, 255, 0, 0,
460 | 127, 255, 0, 45,
461 | 170, 255, 0,255,
462 | 212, 255, 55, 45,
463 | 255, 255,255, 0};
464 |
465 | // Gradient palette "Blue_Cyan_Yellow_gp", originally from
466 | // http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/basic/tn/Blue_Cyan_Yellow.png.index.html
467 | // converted for FastLED with gammas (2.6, 2.2, 2.5)
468 | // Size: 20 bytes of program space.
469 |
470 | DEFINE_GRADIENT_PALETTE( Blue_Cyan_Yellow_gp ) {
471 | 0, 0, 0,255,
472 | 63, 0, 55,255,
473 | 127, 0,255,255,
474 | 191, 42,255, 45,
475 | 255, 255,255, 0};
476 |
477 |
478 | // Single array of defined cpt-city color palettes.
479 | // This will let us programmatically choose one based on
480 | // a number, rather than having to activate each explicitly
481 | // by name every time.
482 | // Since it is const, this array could also be moved
483 | // into PROGMEM to save SRAM, but for simplicity of illustration
484 | // we'll keep it in a regular SRAM array.
485 | //
486 | // This list of color palettes acts as a "playlist"; you can
487 | // add or delete, or re-arrange as you wish.
488 | const TProgmemRGBGradientPalettePtr gGradientPalettes[] = {
489 | Sunset_Real_gp,
490 | es_rivendell_15_gp,
491 | es_ocean_breeze_036_gp,
492 | rgi_15_gp,
493 | retro2_16_gp,
494 | Analogous_1_gp,
495 | es_pinksplash_08_gp,
496 | Coral_reef_gp,
497 | es_ocean_breeze_068_gp,
498 | es_pinksplash_07_gp,
499 | es_vintage_01_gp,
500 | departure_gp,
501 | es_landscape_64_gp,
502 | es_landscape_33_gp,
503 | rainbowsherbet_gp,
504 | gr65_hult_gp,
505 | gr64_hult_gp,
506 | GMT_drywet_gp,
507 | ib_jul01_gp,
508 | es_vintage_57_gp,
509 | ib15_gp,
510 | Fuschia_7_gp,
511 | es_emerald_dragon_08_gp,
512 | lava_gp,
513 | fire_gp,
514 | Colorfull_gp,
515 | Magenta_Evening_gp,
516 | Pink_Purple_gp,
517 | es_autumn_19_gp,
518 | BlacK_Blue_Magenta_White_gp,
519 | BlacK_Magenta_Red_gp,
520 | BlacK_Red_Magenta_Yellow_gp,
521 | Blue_Cyan_Yellow_gp };
522 |
523 |
524 | // Count of how many cpt-city gradients are defined:
525 | const uint8_t gGradientPaletteCount =
526 | sizeof( gGradientPalettes) / sizeof( TProgmemRGBGradientPalettePtr );
527 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/Noise.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Torch: https://github.com/evilgeniuslabs/torch
3 | * Copyright (C) 2015 Jason Coon
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #define MAX_DIMENSION ((MATRIX_WIDTH > MATRIX_HEIGHT) ? MATRIX_WIDTH : MATRIX_HEIGHT)
20 |
21 | // The 16 bit version of our coordinates
22 | static uint16_t noisex;
23 | static uint16_t noisey;
24 | static uint16_t noisez;
25 |
26 | // We're using the x/y dimensions to map to the x/y pixels on the matrix. We'll
27 | // use the z-axis for "time". speed determines how fast time moves forward. Try
28 | // 1 for a very slow moving effect, or 60 for something that ends up looking like
29 | // water.
30 | uint32_t noisespeedx = 1;
31 | uint32_t noisespeedy = 1;
32 | uint32_t noisespeedz = 1;
33 |
34 | // Scale determines how far apart the pixels in our noise matrix are. Try
35 | // changing these values around to see how it affects the motion of the display. The
36 | // higher the value of scale, the more "zoomed out" the noise will be. A value
37 | // of 1 will be so zoomed in, you'll mostly see solid colors.
38 | uint16_t noisescale = 30; // scale is set dynamically once we've started up
39 |
40 | // This is the array that we keep our computed noise values in
41 | uint8_t noise[MAX_DIMENSION][MAX_DIMENSION];
42 |
43 | uint8_t colorLoop = 0;
44 |
45 | CRGBPalette16 blackAndWhiteStripedPalette;
46 |
47 | // This function sets up a palette of black and white stripes,
48 | // using code. Since the palette is effectively an array of
49 | // sixteen CRGB colors, the various fill_* functions can be used
50 | // to set them up.
51 | void SetupBlackAndWhiteStripedPalette()
52 | {
53 | // 'black out' all 16 palette entries...
54 | fill_solid( blackAndWhiteStripedPalette, 16, CRGB::Black);
55 | // and set every fourth one to white.
56 | blackAndWhiteStripedPalette[0] = CRGB::White;
57 | blackAndWhiteStripedPalette[4] = CRGB::White;
58 | blackAndWhiteStripedPalette[8] = CRGB::White;
59 | blackAndWhiteStripedPalette[12] = CRGB::White;
60 |
61 | }
62 |
63 | CRGBPalette16 blackAndBlueStripedPalette;
64 |
65 | // This function sets up a palette of black and blue stripes,
66 | // using code. Since the palette is effectively an array of
67 | // sixteen CRGB colors, the various fill_* functions can be used
68 | // to set them up.
69 | void SetupBlackAndBlueStripedPalette()
70 | {
71 | // 'black out' all 16 palette entries...
72 | fill_solid( blackAndBlueStripedPalette, 16, CRGB::Black);
73 |
74 | for(uint8_t i = 0; i < 6; i++) {
75 | blackAndBlueStripedPalette[i] = CRGB::Blue;
76 | }
77 | }
78 |
79 | // There are several different palettes of colors demonstrated here.
80 | //
81 | // FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,
82 | // OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
83 | //
84 | // Additionally, you can manually define your own color palettes, or you can write
85 | // code that creates color palettes on the fly.
86 |
87 | boolean initialized = false;
88 |
89 | // Fill the x/y array of 8-bit noise values using the inoise8 function.
90 | void fillnoise8() {
91 |
92 | if(!initialized) {
93 | initialized = true;
94 | // Initialize our coordinates to some random values
95 | noisex = random16();
96 | noisey = random16();
97 | noisez = random16();
98 | }
99 |
100 | // If we're runing at a low "speed", some 8-bit artifacts become visible
101 | // from frame-to-frame. In order to reduce this, we can do some fast data-smoothing.
102 | // The amount of data smoothing we're doing depends on "speed".
103 | uint8_t dataSmoothing = 0;
104 | uint16_t lowestNoise = noisespeedx < noisespeedy ? noisespeedx : noisespeedy;
105 | lowestNoise = lowestNoise < noisespeedz ? lowestNoise : noisespeedz;
106 | if( lowestNoise < 8) {
107 | dataSmoothing = 200 - (lowestNoise * 4);
108 | }
109 |
110 | for(int i = 0; i < MAX_DIMENSION; i++) {
111 | int ioffset = noisescale * i;
112 | for(int j = 0; j < MAX_DIMENSION; j++) {
113 | int joffset = noisescale * j;
114 |
115 | uint8_t data = inoise8(noisex + ioffset, noisey + joffset, noisez);
116 |
117 | // The range of the inoise8 function is roughly 16-238.
118 | // These two operations expand those values out to roughly 0..255
119 | // You can comment them out if you want the raw noise data.
120 | data = qsub8(data,16);
121 | data = qadd8(data,scale8(data,39));
122 |
123 | if( dataSmoothing ) {
124 | uint8_t olddata = noise[i][j];
125 | uint8_t newdata = scale8( olddata, dataSmoothing) + scale8( data, 256 - dataSmoothing);
126 | data = newdata;
127 | }
128 |
129 | noise[i][j] = data;
130 | }
131 | }
132 |
133 | noisex += noisespeedx;
134 | noisey += noisespeedy;
135 | noisez += noisespeedz;
136 | }
137 |
138 | void mapNoiseToLEDsUsingPalette(CRGBPalette16 palette, uint8_t hueReduce = 0)
139 | {
140 | static uint8_t ihue=0;
141 |
142 | for(int i = 0; i < MATRIX_WIDTH; i++) {
143 | for(int j = 0; j < MATRIX_HEIGHT; j++) {
144 | // We use the value at the (i,j) coordinate in the noise
145 | // array for our brightness, and the flipped value from (j,i)
146 | // for our pixel's index into the color palette.
147 |
148 | uint8_t index = noise[j][i];
149 | uint8_t bri = noise[i][j];
150 |
151 | // if this palette is a 'loop', add a slowly-changing base value
152 | if( colorLoop) {
153 | index += ihue;
154 | }
155 |
156 | // brighten up, as the color palette itself often contains the
157 | // light/dark dynamic range desired
158 | if( bri > 127 ) {
159 | bri = 255;
160 | } else {
161 | bri = dim8_raw( bri * 2);
162 | }
163 |
164 | if(hueReduce > 0) {
165 | if(index < hueReduce) index = 0;
166 | else index -= hueReduce;
167 | }
168 |
169 | CRGB color = ColorFromPalette( palette, index, bri);
170 | uint16_t n = XY(i, j);
171 |
172 | leds[n] = color;
173 | }
174 | }
175 |
176 | ihue+=1;
177 | }
178 |
179 | uint16_t drawNoise(CRGBPalette16 palette,uint8_t hueReduce = 0) {
180 | // generate noise data
181 | fillnoise8();
182 |
183 | // convert the noise data to colors in the LED array
184 | // using the current palette
185 | mapNoiseToLEDsUsingPalette(palette, hueReduce);
186 |
187 | return 10;
188 | }
189 |
190 | uint16_t rainbowNoise() {
191 | noisespeedx = 9;
192 | noisespeedy = 0;
193 | noisespeedz = 0;
194 | noisescale = 30;
195 | colorLoop = 0;
196 | return drawNoise(RainbowColors_p);
197 | }
198 |
199 | uint16_t rainbowStripeNoise() {
200 | noisespeedx = 9;
201 | noisespeedy = 0;
202 | noisespeedz = 0;
203 | noisescale = 20;
204 | colorLoop = 0;
205 | return drawNoise(RainbowStripeColors_p);
206 | }
207 |
208 | uint16_t partyNoise() {
209 | noisespeedx = 9;
210 | noisespeedy = 0;
211 | noisespeedz = 0;
212 | noisescale = 30;
213 | colorLoop = 0;
214 | return drawNoise(PartyColors_p);
215 | }
216 |
217 | uint16_t forestNoise() {
218 | noisespeedx = 9;
219 | noisespeedy = 0;
220 | noisespeedz = 0;
221 | noisescale = 120;
222 | colorLoop = 0;
223 | return drawNoise(ForestColors_p);
224 | }
225 |
226 | uint16_t cloudNoise() {
227 | noisespeedx = 9;
228 | noisespeedy = 0;
229 | noisespeedz = 0;
230 | noisescale = 30;
231 | colorLoop = 0;
232 | return drawNoise(CloudColors_p);
233 | }
234 |
235 | uint16_t fireNoise() {
236 | noisespeedx = 8; // 24;
237 | noisespeedy = 0;
238 | noisespeedz = 8;
239 | noisescale = 50;
240 | colorLoop = 0;
241 | return drawNoise(HeatColors_p, 60);
242 | }
243 |
244 | uint16_t lavaNoise() {
245 | noisespeedx = 32;
246 | noisespeedy = 0;
247 | noisespeedz = 16;
248 | noisescale = 50;
249 | colorLoop = 0;
250 | return drawNoise(LavaColors_p);
251 | }
252 |
253 | uint16_t oceanNoise() {
254 | noisespeedx = 9;
255 | noisespeedy = 0;
256 | noisespeedz = 0;
257 | noisescale = 90;
258 | colorLoop = 0;
259 | return drawNoise(OceanColors_p);
260 | }
261 |
262 | uint16_t blackAndWhiteNoise() {
263 | SetupBlackAndWhiteStripedPalette();
264 | noisespeedx = 9;
265 | noisespeedy = 0;
266 | noisespeedz = 0;
267 | noisescale = 30;
268 | colorLoop = 0;
269 | return drawNoise(blackAndWhiteStripedPalette);
270 | }
271 |
272 | uint16_t blackAndBlueNoise() {
273 | SetupBlackAndBlueStripedPalette();
274 | noisespeedx = 9;
275 | noisespeedy = 0;
276 | noisespeedz = 0;
277 | noisescale = 30;
278 | colorLoop = 0;
279 | return drawNoise(blackAndBlueStripedPalette);
280 | }
281 |
--------------------------------------------------------------------------------
/Pulse.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Torch: https://github.com/evilgeniuslabs/torch
3 | * Copyright (C) 2015 Jason Coon
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | uint16_t pulse() {
20 | // palette = RainbowColors_p;
21 |
22 | static uint8_t hue = 0;
23 | static uint8_t centerX = 0;
24 | static uint8_t centerY = 0;
25 | static uint8_t step = 0;
26 |
27 | static const uint8_t maxSteps = 16;
28 | static const float fadeRate = 0.8;
29 |
30 | dimAll(235);
31 |
32 | if (step == 0) {
33 | centerX = random(32);
34 | centerY = random(32);
35 | hue = random(256); // 170;
36 |
37 | drawCircle(centerX, centerY, step, ColorFromPalette(palette, hue));
38 | step++;
39 | }
40 | else {
41 | if (step < maxSteps) {
42 | // initial pulse
43 | drawCircle(centerX, centerY, step, ColorFromPalette(palette, hue, pow(fadeRate, step - 2) * 255));
44 |
45 | // secondary pulse
46 | if (step > 3) {
47 | drawCircle(centerX, centerY, step - 3, ColorFromPalette(palette, hue, pow(fadeRate, step - 2) * 255));
48 | }
49 | step++;
50 | }
51 | else {
52 | step = 0;
53 | }
54 | }
55 |
56 | return 30;
57 | }
58 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Torch
2 | Cylindrical light art display.
3 |
4 | [v2 Demo Video](https://youtu.be/FigdmlocAUE?list=PLUYGVM-2vDxK88TIxaxSD_qWTSBVVwPWg):
5 |
6 | [](https://youtu.be/FigdmlocAUE?list=PLUYGVM-2vDxK88TIxaxSD_qWTSBVVwPWg)
7 |
8 | [v1 Demo Video](https://www.youtube.com/watch?v=MlNcL1obSB0):
9 |
10 | [](https://www.youtube.com/watch?v=MlNcL1obSB0)
11 |
12 | Available from Evil Genius Labs: http://www.evilgeniuslabs.org
13 |
14 | Cylindrical, music-reactive light art display, built with 240 WS2812B RGB LEDs, controlled with a Particle Photon or Teensy, using the FastLED library.
15 |
16 | Controlled via an app or webpage over Wi-Fi, and/or a wireless infrared remote control.
17 |
18 | Comes with over 20 patterns built-in.
19 |
20 | Programmable over Wi-Fi or micro USB cable.
21 |
22 | Firmware and all patterns are fully open-source.
23 |
--------------------------------------------------------------------------------
/Torch.h:
--------------------------------------------------------------------------------
1 | // Slightly modified version of the fire pattern from MessageTorch by Lukas Zeller:
2 | // https://github.com/plan44/messagetorch
3 |
4 | // The MIT License (MIT)
5 |
6 | // Copyright (c) 2014 Lukas Zeller
7 |
8 | // Permission is hereby granted, free of charge, to any person obtaining a copy of
9 | // this software and associated documentation files (the "Software"), to deal in
10 | // the Software without restriction, including without limitation the rights to
11 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12 | // the Software, and to permit persons to whom the Software is furnished to do so,
13 | // subject to the following conditions:
14 |
15 | // The above copyright notice and this permission notice shall be included in all
16 | // copies or substantial portions of the Software.
17 |
18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
20 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 |
25 | // torch parameters
26 |
27 | uint16_t cycle_wait = 1; // 0..255
28 |
29 | byte flame_min = 100; // 0..255
30 | byte flame_max = 220; // 0..255
31 |
32 | byte random_spark_probability = 2; // 0..100
33 | byte spark_min = 200; // 0..255
34 | byte spark_max = 255; // 0..255
35 |
36 | byte spark_tfr = 40; // 0..256 how much energy is transferred up for a spark per cycle
37 | uint16_t spark_cap = 200; // 0..255: spark cells: how much energy is retained from previous cycle
38 |
39 | uint16_t up_rad = 40; // up radiation
40 | uint16_t side_rad = 35; // sidewards radiation
41 | uint16_t heat_cap = 0; // 0..255: passive cells: how much energy is retained from previous cycle
42 |
43 | byte red_bg = 0;
44 | byte green_bg = 0;
45 | byte blue_bg = 0;
46 | byte red_bias = 10;
47 | byte green_bias = 0;
48 | byte blue_bias = 0;
49 | int red_energy = 180;
50 | int green_energy = 20; // 145;
51 | int blue_energy = 0;
52 |
53 | byte upside_down = 0; // if set, flame (or rather: drop) animation is upside down. Text remains as-is
54 |
55 | // torch mode
56 | // ==========
57 |
58 | #define numLeds NUM_LEDS
59 | #define ledsPerLevel MATRIX_WIDTH
60 | #define levels MATRIX_HEIGHT
61 |
62 | byte currentEnergy[numLeds]; // current energy level
63 | byte nextEnergy[numLeds]; // next energy level
64 | byte energyMode[numLeds]; // mode how energy is calculated for this point
65 |
66 | enum {
67 | torch_passive = 0, // just environment, glow from nearby radiation
68 | torch_nop = 1, // no processing
69 | torch_spark = 2, // slowly looses energy, moves up
70 | torch_spark_temp = 3, // a spark still getting energy from the level below
71 | };
72 |
73 | inline void reduce(byte &aByte, byte aAmount, byte aMin = 0)
74 | {
75 | int r = aByte-aAmount;
76 | if (raMax)
87 | aByte = aMax;
88 | else
89 | aByte = (byte)r;
90 | }
91 |
92 | uint16_t random2(uint16_t aMinOrMax, uint16_t aMax = 0)
93 | {
94 | if (aMax==0) {
95 | aMax = aMinOrMax;
96 | aMinOrMax = 0;
97 | }
98 | uint32_t r = aMinOrMax;
99 | aMax = aMax - aMinOrMax + 1;
100 | r += rand() % aMax;
101 | return r;
102 | }
103 |
104 | void resetEnergy()
105 | {
106 | for (int i=0; i>8;
140 | // this cell becomes active spark
141 | energyMode[i] = torch_spark;
142 | }
143 | else {
144 | increase(e, spark_tfr);
145 | }
146 | break;
147 | }
148 | case torch_passive: {
149 | e = ((int)e*heat_cap)>>8;
150 | increase(e, ((((int)currentEnergy[i-1]+(int)currentEnergy[i+1])*side_rad)>>9) + (((int)currentEnergy[i-ledsPerLevel]*up_rad)>>8));
151 | }
152 | default:
153 | break;
154 | }
155 | nextEnergy[i++] = e;
156 | }
157 | }
158 | }
159 |
160 | const uint8_t energymap[32] = {0, 64, 96, 112, 128, 144, 152, 160, 168, 176, 184, 184, 192, 200, 200, 208, 208, 216, 216, 224, 224, 224, 232, 232, 232, 240, 240, 240, 240, 248, 248, 248};
161 |
162 | void calcNextColors()
163 | {
164 | for (int i=0; i250)
173 | leds[i] = CRGB(170, 170, e); // blueish extra-bright spark
174 | else {
175 | if (e>0) {
176 | // energy to brightness is non-linear
177 | byte eb = energymap[e>>3];
178 | byte r = red_bias;
179 | byte g = green_bias;
180 | byte b = blue_bias;
181 | increase(r, (eb*red_energy)>>8);
182 | increase(g, (eb*green_energy)>>8);
183 | increase(b, (eb*blue_energy)>>8);
184 | leds[i] = CRGB(r, g, b);
185 | }
186 | else {
187 | // background, no energy
188 | leds[i] = CRGB(red_bg, green_bg, blue_bg);
189 | }
190 | }
191 | }
192 | }
193 |
194 | void injectRandom()
195 | {
196 | // random flame energy at bottom row
197 | for (int i=0; i.
17 | */
18 |
19 | uint16_t wave() {
20 | static byte rotation = 3;
21 |
22 | static const uint8_t scaleWidth = 256 / MATRIX_WIDTH;
23 | static const uint8_t scaleHeight = 256 / MATRIX_HEIGHT;
24 |
25 | static const uint8_t maxX = MATRIX_WIDTH - 1;
26 | static const uint8_t maxY = MATRIX_HEIGHT - 1;
27 |
28 | static uint8_t waveCount = 1;
29 | static uint8_t hue = 1;
30 | static uint8_t theta = 0;
31 |
32 | // EVERY_N_SECONDS(10) {
33 | // rotation = random(0, 1);
34 | // waveCount = random(1, 3);
35 | // }
36 |
37 | int n = 0;
38 |
39 | switch (rotation) {
40 | case 0:
41 | for (int x = 0; x < MATRIX_WIDTH; x++) {
42 | n = quadwave8(x * 2 + theta) / scaleHeight;
43 | leds[XY(x, n)] = ColorFromPalette(palette, x + hue);
44 | if (waveCount == 2)
45 | leds[XY(x, maxY - n)] = ColorFromPalette(palette, x + hue);
46 | }
47 | break;
48 |
49 | case 1:
50 | for (int y = 0; y < MATRIX_HEIGHT; y++) {
51 | n = quadwave8(y * 2 + theta) / scaleWidth;
52 | leds[XY(n, y)] = ColorFromPalette(palette, y + hue);
53 | if (waveCount == 2)
54 | leds[XY(maxX - n, y)] = ColorFromPalette(palette, y + hue);
55 | }
56 | break;
57 |
58 | case 2:
59 | for (int x = 0; x < MATRIX_WIDTH; x++) {
60 | n = quadwave8(x * 2 - theta) / scaleHeight;
61 | leds[XY(x, n)] = ColorFromPalette(palette, x + hue);
62 | if (waveCount == 2)
63 | leds[XY(x, maxY - n)] = ColorFromPalette(palette, x + hue);
64 | }
65 | break;
66 |
67 | case 3:
68 | for (int y = 0; y < MATRIX_HEIGHT; y++) {
69 | n = quadwave8(y * 2 - theta) / scaleWidth;
70 | leds[XY(n, y)] = ColorFromPalette(palette, y + hue);
71 | if (waveCount == 2)
72 | leds[XY(maxX - n, y)] = ColorFromPalette(palette, y + hue);
73 | }
74 | break;
75 | }
76 |
77 | dimAll(254);
78 |
79 | EVERY_N_MILLISECONDS(10) {
80 | theta++;
81 | hue++;
82 | }
83 |
84 | return 0;
85 | }
86 |
--------------------------------------------------------------------------------
/torch.ino:
--------------------------------------------------------------------------------
1 | /*
2 | * Torch: https://github.com/evilgeniuslabs/torch
3 | * Copyright (C) 2015 Jason Coon
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include
20 | #include
21 | #include
22 | #include
23 |
24 | #if FASTLED_VERSION < 3001000
25 | #error "Requires FastLED 3.1 or later; check github for latest code."
26 | #endif
27 |
28 | #define LED_PIN 11
29 | #define IR_RECV_PIN 12
30 | #define COLOR_ORDER GRB
31 | #define CHIPSET WS2812B
32 | #define NUM_LEDS 240
33 |
34 | const uint8_t MATRIX_WIDTH = 14;
35 | const uint8_t MATRIX_HEIGHT = 17;
36 |
37 | const int MATRIX_CENTER_X = MATRIX_WIDTH / 2;
38 | const int MATRIX_CENTER_Y = MATRIX_HEIGHT / 2;
39 |
40 | const byte MATRIX_CENTRE_X = MATRIX_CENTER_X - 1;
41 | const byte MATRIX_CENTRE_Y = MATRIX_CENTER_Y - 1;
42 |
43 | const uint8_t brightnessCount = 5;
44 | uint8_t brightnessMap[brightnessCount] = { 16, 32, 64, 128, 255 };
45 | uint8_t brightness = brightnessMap[0];
46 |
47 | CRGB leds[NUM_LEDS + 1];
48 | IRrecv irReceiver(IR_RECV_PIN);
49 |
50 | #define BUTTON_1_PIN 16
51 | #define BUTTON_2_PIN 17
52 |
53 | Bounce button1 = Bounce();
54 | Bounce button2 = Bounce();
55 |
56 | #include "Commands.h"
57 | #include "GradientPalettes.h"
58 |
59 | CRGB solidColor = CRGB::White;
60 |
61 | typedef uint16_t(*PatternFunctionPointer)();
62 | typedef PatternFunctionPointer PatternList [];
63 | #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
64 |
65 | int autoPlayDurationSeconds = 10;
66 | unsigned int autoPlayTimout = 0;
67 | bool autoplayEnabled = false;
68 |
69 | InputCommand command;
70 |
71 | int currentPatternIndex = 0;
72 | PatternFunctionPointer currentPattern;
73 |
74 | CRGB w(85, 85, 85), W(CRGB::White);
75 | CRGBPalette16 snowColors = CRGBPalette16( W, W, W, W, w, w, w, w, w, w, w, w, w, w, w, w );
76 |
77 | CRGB l(0xE1A024);
78 | CRGBPalette16 incandescentColors = CRGBPalette16( l, l, l, l, l, l, l, l, l, l, l, l, l, l, l, l );
79 |
80 | const CRGBPalette16 palettes[] = {
81 | RainbowColors_p,
82 | RainbowStripeColors_p,
83 | OceanColors_p,
84 | CloudColors_p,
85 | ForestColors_p,
86 | PartyColors_p,
87 | HeatColors_p,
88 | LavaColors_p,
89 | snowColors,
90 | };
91 |
92 | const int paletteCount = ARRAY_SIZE(palettes);
93 |
94 | int currentPaletteIndex = 0;
95 | CRGBPalette16 palette = palettes[0];
96 |
97 | uint8_t gHue = 0; // rotating "base color" used by many of the patterns
98 |
99 | #include "Drawing.h"
100 | #include "Effects.h"
101 |
102 | #include "Noise.h"
103 | #include "Pulse.h"
104 | #include "Wave.h"
105 | #include "Fire2012WithPalette.h"
106 | #include "Torch.h"
107 | #include "AudioLogic.h"
108 | #include "AudioPatterns.h"
109 |
110 | const PatternList patterns = {
111 | analyzerColumns,
112 | analyzerColumnsSolid,
113 | analyzerPixels,
114 | fallingSpectrogram,
115 | audioFire,
116 | rainbowAudioNoise,
117 | rainbowStripeAudioNoise,
118 | partyAudioNoise,
119 | forestAudioNoise,
120 | cloudAudioNoise,
121 | fireAudioNoise,
122 | lavaAudioNoise,
123 | oceanAudioNoise,
124 | blackAndWhiteAudioNoise,
125 | blackAndBlueAudioNoise,
126 | fireNoise,
127 | lavaNoise,
128 | torch,
129 | fire2012WithPalette,
130 | rainbowNoise,
131 | rainbowStripeNoise,
132 | partyNoise,
133 | forestNoise,
134 | cloudNoise,
135 | oceanNoise,
136 | blackAndWhiteNoise,
137 | blackAndBlueNoise,
138 | pulse,
139 | wave,
140 | pride,
141 | colorWaves,
142 | rainbow,
143 | rainbowWithGlitter,
144 | confetti,
145 | bpm,
146 | juggle,
147 | sinelon,
148 | hueCycle,
149 | rainbowTwinkles,
150 | snowTwinkles,
151 | cloudTwinkles,
152 | incandescentTwinkles,
153 | fireflies,
154 | showSolidColor
155 | };
156 |
157 | const int patternCount = ARRAY_SIZE(patterns);
158 |
159 | void setup() {
160 | delay(500); // sanity delay
161 | // Serial.begin(9600);
162 | // Serial.println("setup start");
163 |
164 | loadSettings();
165 |
166 | FastLED.addLeds(leds, NUM_LEDS);
167 | FastLED.setCorrection(TypicalLEDStrip);
168 | FastLED.setBrightness(brightness);
169 | // FastLED.setDither(false);
170 | FastLED.setDither(brightness < 255);
171 |
172 | // Initialize the IR receiver
173 | irReceiver.enableIRIn();
174 | irReceiver.blink13(true);
175 |
176 | pinMode(BUTTON_1_PIN, INPUT_PULLUP);
177 | pinMode(BUTTON_2_PIN, INPUT_PULLUP);
178 | button1.attach(BUTTON_1_PIN);
179 | button2.attach(BUTTON_2_PIN);
180 | button1.interval(5);
181 | button2.interval(5);
182 |
183 | currentPattern = patterns[currentPatternIndex];
184 |
185 | autoPlayTimout = millis() + (autoPlayDurationSeconds * 1000);
186 |
187 | initializeAudio();
188 |
189 | // Serial.println("setup end");
190 | }
191 |
192 | void loop() {
193 | // Add entropy to random number generator; we use a lot of it.
194 | random16_add_entropy(random());
195 |
196 | EVERY_N_MILLISECONDS(30) {
197 | readAudio();
198 | }
199 |
200 | uint16_t requestedDelay = currentPattern();
201 |
202 | FastLED.show(); // display this frame
203 |
204 | handleInput(requestedDelay);
205 |
206 | if (autoplayEnabled && millis() > autoPlayTimout) {
207 | move(1);
208 | autoPlayTimout = millis() + (autoPlayDurationSeconds * 1000);
209 | }
210 |
211 | // do some periodic updates
212 | EVERY_N_MILLISECONDS(20) {
213 | gHue++; // slowly cycle the "base color" through the rainbow
214 | }
215 | }
216 |
217 | void loadSettings() {
218 | // load settings from EEPROM
219 |
220 | // brightness
221 | brightness = EEPROM.read(0);
222 | if (brightness < 1)
223 | brightness = 1;
224 | else if (brightness > 255)
225 | brightness = 255;
226 |
227 | // currentPatternIndex
228 | currentPatternIndex = EEPROM.read(1);
229 | if (currentPatternIndex < 0)
230 | currentPatternIndex = 0;
231 | else if (currentPatternIndex >= patternCount)
232 | currentPatternIndex = patternCount - 1;
233 |
234 | // solidColor
235 | solidColor.r = EEPROM.read(2);
236 | solidColor.g = EEPROM.read(3);
237 | solidColor.b = EEPROM.read(4);
238 |
239 | if (solidColor.r == 0 && solidColor.g == 0 && solidColor.b == 0)
240 | solidColor = CRGB::White;
241 | }
242 |
243 | void setSolidColor(CRGB color) {
244 | solidColor = color;
245 |
246 | EEPROM.write(2, solidColor.r);
247 | EEPROM.write(3, solidColor.g);
248 | EEPROM.write(4, solidColor.b);
249 |
250 | moveTo(patternCount - 1);
251 | }
252 |
253 | void powerOff()
254 | {
255 | // clear the display
256 | const uint8_t stepSize = 4;
257 |
258 | for (uint8_t i = 0; i < NUM_LEDS / 2 - stepSize; i += stepSize) {
259 | for (uint8_t j = 0; j < stepSize; j++) {
260 | leds[i + j] = CRGB::Black;
261 | leds[(NUM_LEDS - 1) - (i + j)] = CRGB::Black;
262 | }
263 | FastLED.show(); // display this frame
264 | }
265 |
266 | fill_solid(leds, NUM_LEDS, CRGB::Black);
267 |
268 | FastLED.show(); // display this frame
269 |
270 | while (true) {
271 | // check for physical button input
272 | button1.update();
273 | button2.update();
274 |
275 | if (button1.rose() || button2.rose()) {
276 | Serial.println("Button released");
277 | return;
278 | }
279 |
280 | // check for ir remote input
281 | InputCommand command = readCommand();
282 | if (command != InputCommand::None)
283 | return;
284 | }
285 | }
286 |
287 | void move(int delta) {
288 | moveTo(currentPatternIndex + delta);
289 | }
290 |
291 | void moveTo(int index) {
292 | currentPatternIndex = index;
293 |
294 | if (currentPatternIndex >= patternCount)
295 | currentPatternIndex = 0;
296 | else if (currentPatternIndex < 0)
297 | currentPatternIndex = patternCount - 1;
298 |
299 | currentPattern = patterns[currentPatternIndex];
300 |
301 | fill_solid(leds, NUM_LEDS, CRGB::Black);
302 |
303 | EEPROM.write(1, currentPatternIndex);
304 | }
305 |
306 | int getBrightnessLevel() {
307 | int level = 0;
308 | for (int i = 0; i < brightnessCount; i++) {
309 | if (brightnessMap[i] >= brightness) {
310 | level = i;
311 | break;
312 | }
313 | }
314 | return level;
315 | }
316 |
317 | uint8_t cycleBrightness() {
318 | adjustBrightness(1);
319 |
320 | if (brightness == brightnessMap[0])
321 | return 0;
322 |
323 | return brightness;
324 | }
325 |
326 | void adjustBrightness(int delta) {
327 | int level = getBrightnessLevel();
328 |
329 | level += delta;
330 |
331 | // don't wrap
332 | if (level < 0)
333 | level = 0;
334 | if (level >= brightnessCount)
335 | level = brightnessCount - 1;
336 |
337 | brightness = brightnessMap[level];
338 | FastLED.setBrightness(brightness);
339 | FastLED.setDither(brightness < 255);
340 |
341 | EEPROM.write(0, brightness);
342 | }
343 |
344 | void cyclePalette(int delta = 1) {
345 | if (currentPaletteIndex == 0 && delta < 0)
346 | currentPaletteIndex = paletteCount - 1;
347 | else if (currentPaletteIndex >= paletteCount - 1 && delta > 0)
348 | currentPaletteIndex = 0;
349 | else
350 | currentPaletteIndex += delta;
351 |
352 | if (currentPaletteIndex >= paletteCount)
353 | currentPaletteIndex = 0;
354 |
355 | palette = palettes[currentPaletteIndex];
356 | }
357 |
358 | unsigned long button1PressTimeStamp;
359 | unsigned long button2PressTimeStamp;
360 |
361 | void handleInput(unsigned int requestedDelay) {
362 | unsigned int requestedDelayTimeout = millis() + requestedDelay;
363 |
364 | while (true) {
365 | // check for physical button input
366 | button1.update();
367 | button2.update();
368 |
369 | if (button1.fell()) {
370 | Serial.println("Button 1 depressed");
371 | button1PressTimeStamp = millis();
372 | }
373 |
374 | if (button2.fell()) {
375 | Serial.println("Button 2 depressed");
376 | button2PressTimeStamp = millis();
377 | }
378 |
379 | if (button1.rose()) {
380 | Serial.println("Button 1 released");
381 | move(1);
382 | }
383 |
384 | if (button2.rose()) {
385 | Serial.println("Button 2 released");
386 | powerOff();
387 | break;
388 | }
389 |
390 | command = readCommand(defaultHoldDelay);
391 |
392 | if (command != InputCommand::None) {
393 | // Serial.print("command: ");
394 | // Serial.println((int) command);
395 | }
396 |
397 | if (command == InputCommand::Up) {
398 | move(1);
399 | break;
400 | }
401 | else if (command == InputCommand::Down) {
402 | move(-1);
403 | break;
404 | }
405 | else if (command == InputCommand::Brightness) {
406 | if (isHolding || cycleBrightness() == 0) {
407 | heldButtonHasBeenHandled();
408 | powerOff();
409 | break;
410 | }
411 | }
412 | else if (command == InputCommand::Power) {
413 | powerOff();
414 | break;
415 | }
416 | else if (command == InputCommand::BrightnessUp) {
417 | adjustBrightness(1);
418 | }
419 | else if (command == InputCommand::BrightnessDown) {
420 | adjustBrightness(-1);
421 | }
422 | else if (command == InputCommand::PlayMode) { // toggle pause/play
423 | autoplayEnabled = !autoplayEnabled;
424 | }
425 | else if (command == InputCommand::NextPalette) { // cycle color palette
426 | cyclePalette(1);
427 | }
428 | else if (command == InputCommand::PreviousPalette) { // cycle color palette
429 | cyclePalette(-1);
430 | }
431 |
432 | // pattern buttons
433 |
434 | else if (command == InputCommand::Pattern1) {
435 | moveTo(0);
436 | break;
437 | }
438 | else if (command == InputCommand::Pattern2) {
439 | moveTo(1);
440 | break;
441 | }
442 | else if (command == InputCommand::Pattern3) {
443 | moveTo(2);
444 | break;
445 | }
446 | else if (command == InputCommand::Pattern4) {
447 | moveTo(3);
448 | break;
449 | }
450 | else if (command == InputCommand::Pattern5) {
451 | moveTo(4);
452 | break;
453 | }
454 | else if (command == InputCommand::Pattern6) {
455 | moveTo(5);
456 | break;
457 | }
458 | else if (command == InputCommand::Pattern7) {
459 | moveTo(6);
460 | break;
461 | }
462 | else if (command == InputCommand::Pattern8) {
463 | moveTo(7);
464 | break;
465 | }
466 | else if (command == InputCommand::Pattern9) {
467 | moveTo(8);
468 | break;
469 | }
470 | else if (command == InputCommand::Pattern10) {
471 | moveTo(9);
472 | break;
473 | }
474 | else if (command == InputCommand::Pattern11) {
475 | moveTo(10);
476 | break;
477 | }
478 | else if (command == InputCommand::Pattern12) {
479 | moveTo(11);
480 | break;
481 | }
482 |
483 | // custom color adjustment buttons
484 |
485 | else if (command == InputCommand::RedUp) {
486 | solidColor.red += 1;
487 | setSolidColor(solidColor);
488 | break;
489 | }
490 | else if (command == InputCommand::RedDown) {
491 | solidColor.red -= 1;
492 | setSolidColor(solidColor);
493 | break;
494 | }
495 | else if (command == InputCommand::GreenUp) {
496 | solidColor.green += 1;
497 | setSolidColor(solidColor); \
498 | break;
499 | }
500 | else if (command == InputCommand::GreenDown) {
501 | solidColor.green -= 1;
502 | setSolidColor(solidColor);
503 | break;
504 | }
505 | else if (command == InputCommand::BlueUp) {
506 | solidColor.blue += 1;
507 | setSolidColor(solidColor);
508 | break;
509 | }
510 | else if (command == InputCommand::BlueDown) {
511 | solidColor.blue -= 1;
512 | setSolidColor(solidColor);
513 | break;
514 | }
515 |
516 | // color buttons
517 |
518 | else if (command == InputCommand::Red && currentPatternIndex != patternCount - 2 && currentPatternIndex != patternCount - 3) { // Red, Green, and Blue buttons can be used by ColorInvaders game, which is the next to last pattern
519 | setSolidColor(CRGB::Red);
520 | break;
521 | }
522 | else if (command == InputCommand::RedOrange) {
523 | setSolidColor(CRGB::OrangeRed);
524 | break;
525 | }
526 | else if (command == InputCommand::Orange) {
527 | setSolidColor(CRGB::Orange);
528 | break;
529 | }
530 | else if (command == InputCommand::YellowOrange) {
531 | setSolidColor(CRGB::Goldenrod);
532 | break;
533 | }
534 | else if (command == InputCommand::Yellow) {
535 | setSolidColor(CRGB::Yellow);
536 | break;
537 | }
538 |
539 | else if (command == InputCommand::Green && currentPatternIndex != patternCount - 2 && currentPatternIndex != patternCount - 3) { // Red, Green, and Blue buttons can be used by ColorInvaders game, which is the next to last pattern
540 | setSolidColor(CRGB::Green);
541 | break;
542 | }
543 | else if (command == InputCommand::Lime) {
544 | setSolidColor(CRGB::Lime);
545 | break;
546 | }
547 | else if (command == InputCommand::Aqua) {
548 | setSolidColor(CRGB::Aqua);
549 | break;
550 | }
551 | else if (command == InputCommand::Teal) {
552 | setSolidColor(CRGB::Teal);
553 | break;
554 | }
555 | else if (command == InputCommand::Navy) {
556 | setSolidColor(CRGB::Navy);
557 | break;
558 | }
559 |
560 | else if (command == InputCommand::Blue && currentPatternIndex != patternCount - 2 && currentPatternIndex != patternCount - 3) { // Red, Green, and Blue buttons can be used by ColorInvaders game, which is the next to last pattern
561 | setSolidColor(CRGB::Blue);
562 | break;
563 | }
564 | else if (command == InputCommand::RoyalBlue) {
565 | setSolidColor(CRGB::RoyalBlue);
566 | break;
567 | }
568 | else if (command == InputCommand::Purple) {
569 | setSolidColor(CRGB::Purple);
570 | break;
571 | }
572 | else if (command == InputCommand::Indigo) {
573 | setSolidColor(CRGB::Indigo);
574 | break;
575 | }
576 | else if (command == InputCommand::Magenta) {
577 | setSolidColor(CRGB::Magenta);
578 | break;
579 | }
580 |
581 | else if (command == InputCommand::White && currentPatternIndex != patternCount - 2 && currentPatternIndex != patternCount - 3) {
582 | setSolidColor(CRGB::White);
583 | break;
584 | }
585 | else if (command == InputCommand::Pink) {
586 | setSolidColor(CRGB::Pink);
587 | break;
588 | }
589 | else if (command == InputCommand::LightPink) {
590 | setSolidColor(CRGB::LightPink);
591 | break;
592 | }
593 | else if (command == InputCommand::BabyBlue) {
594 | setSolidColor(CRGB::CornflowerBlue);
595 | break;
596 | }
597 | else if (command == InputCommand::LightBlue) {
598 | setSolidColor(CRGB::LightBlue);
599 | break;
600 | }
601 |
602 | if (millis() >= requestedDelayTimeout)
603 | break;
604 | }
605 | }
606 |
607 | uint16_t XY( uint8_t x, uint8_t y) // maps the matrix to the strip
608 | {
609 | uint16_t i;
610 | i = (y * MATRIX_WIDTH) + (MATRIX_WIDTH - x);
611 |
612 | i = (NUM_LEDS - 1) - i;
613 |
614 | if (i > NUM_LEDS)
615 | i = NUM_LEDS;
616 |
617 | return i;
618 | }
619 |
620 | // scale the brightness of the screenbuffer down
621 | void dimAll(byte value)
622 | {
623 | for (int i = 0; i < NUM_LEDS; i++) {
624 | leds[i].nscale8(value);
625 | }
626 | }
627 |
628 | uint16_t showSolidColor() {
629 | fill_solid(leds, NUM_LEDS, solidColor);
630 |
631 | return 60;
632 | }
633 |
634 | uint16_t rainbow()
635 | {
636 | // FastLED's built-in rainbow generator
637 | fill_rainbow(leds, NUM_LEDS, gHue, 1);
638 |
639 | return 8;
640 | }
641 |
642 | uint16_t rainbowWithGlitter()
643 | {
644 | // built-in FastLED rainbow, plus some random sparkly glitter
645 | rainbow();
646 | addGlitter(80);
647 | return 8;
648 | }
649 |
650 | void addGlitter(fract8 chanceOfGlitter)
651 | {
652 | if (random8() < chanceOfGlitter) {
653 | leds[random16(NUM_LEDS)] += CRGB::White;
654 | }
655 | }
656 |
657 | uint16_t confetti()
658 | {
659 | // random colored speckles that blink in and fade smoothly
660 | fadeToBlackBy(leds, NUM_LEDS, 10);
661 | int pos = random16(NUM_LEDS);
662 | leds[pos] += ColorFromPalette(palette, gHue + random8(64), 255); // CHSV(gHue + random8(64), 200, 255);
663 | return 8;
664 | }
665 |
666 | uint16_t bpm()
667 | {
668 | // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
669 | uint8_t BeatsPerMinute = 62;
670 | uint8_t beat = beatsin8(BeatsPerMinute, 64, 255);
671 | for (int i = 0; i < NUM_LEDS; i++) { //9948
672 | leds[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
673 | }
674 | return 8;
675 | }
676 |
677 | uint16_t juggle() {
678 | // N colored dots, weaving in and out of sync with each other
679 | fadeToBlackBy(leds, NUM_LEDS, 20);
680 | byte dothue = 0;
681 | byte dotCount = 3;
682 | for (int i = 0; i < dotCount; i++) {
683 | leds[beatsin16(i + dotCount - 1, 0, NUM_LEDS)] |= CHSV(dothue, 200, 255);
684 | dothue += 256 / dotCount;
685 | }
686 | return 0;
687 | }
688 |
689 | // An animation to play while the crowd goes wild after the big performance
690 | uint16_t applause()
691 | {
692 | static uint16_t lastPixel = 0;
693 | fadeToBlackBy(leds, NUM_LEDS, 32);
694 | leds[lastPixel] = CHSV(random8(HUE_BLUE, HUE_PURPLE), 255, 255);
695 | lastPixel = random16(NUM_LEDS);
696 | leds[lastPixel] = CRGB::White;
697 | return 8;
698 | }
699 |
700 | // An "animation" to just fade to black. Useful as the last track
701 | // in a non-looping performance-oriented playlist.
702 | uint16_t fadeToBlack()
703 | {
704 | fadeToBlackBy(leds, NUM_LEDS, 10);
705 | return 8;
706 | }
707 |
708 | uint16_t sinelon()
709 | {
710 | // a colored dot sweeping back and forth, with fading trails
711 | fadeToBlackBy( leds, NUM_LEDS, 20);
712 | uint16_t pos = beatsin16(13, 0, NUM_LEDS);
713 | static uint16_t prevpos = 0;
714 | if ( pos < prevpos ) {
715 | fill_solid( leds + pos, (prevpos - pos) + 1, CHSV(gHue, 220, 255));
716 | } else {
717 | fill_solid( leds + prevpos, (pos - prevpos) + 1, CHSV( gHue, 220, 255));
718 | }
719 | prevpos = pos;
720 |
721 | return 8;
722 | }
723 |
724 | uint16_t hueCycle() {
725 | fill_solid(leds, NUM_LEDS, CHSV(gHue, 255, 255));
726 | return 60;
727 | }
728 |
729 | // Pride2015 by Mark Kriegsman
730 | // https://gist.github.com/kriegsman/964de772d64c502760e5
731 |
732 | // This function draws rainbows with an ever-changing,
733 | // widely-varying set of parameters.
734 | uint16_t pride()
735 | {
736 | static uint16_t sPseudotime = 0;
737 | static uint16_t sLastMillis = 0;
738 | static uint16_t sHue16 = 0;
739 |
740 | uint8_t sat8 = beatsin88(87, 220, 250);
741 | uint8_t brightdepth = beatsin88(341, 96, 224);
742 | uint16_t brightnessthetainc16 = beatsin88(203, (25 * 256), (40 * 256));
743 | uint8_t msmultiplier = beatsin88(147, 23, 60);
744 |
745 | uint16_t hue16 = sHue16;//gHue * 256;
746 | uint16_t hueinc16 = beatsin88(113, 1, 3000);
747 |
748 | uint16_t ms = millis();
749 | uint16_t deltams = ms - sLastMillis;
750 | sLastMillis = ms;
751 | sPseudotime += deltams * msmultiplier;
752 | sHue16 += deltams * beatsin88(400, 5, 9);
753 | uint16_t brightnesstheta16 = sPseudotime;
754 |
755 | for (int i = 0; i < NUM_LEDS; i++) {
756 | hue16 += hueinc16;
757 | uint8_t hue8 = hue16 / 256;
758 |
759 | brightnesstheta16 += brightnessthetainc16;
760 | uint16_t b16 = sin16(brightnesstheta16) + 32768;
761 |
762 | uint16_t bri16 = (uint32_t) ((uint32_t) b16 * (uint32_t) b16) / 65536;
763 | uint8_t bri8 = (uint32_t) (((uint32_t) bri16) * brightdepth) / 65536;
764 | bri8 += (255 - brightdepth);
765 |
766 | CRGB newcolor = CHSV(hue8, sat8, bri8);
767 |
768 | uint8_t pixelnumber = i;
769 | pixelnumber = (NUM_LEDS - 1) - pixelnumber;
770 |
771 | nblend(leds[pixelnumber], newcolor, 64);
772 | }
773 |
774 | return 0;
775 | }
776 |
777 | ///////////////////////////////////////////////////////////////////////
778 |
779 | // Forward declarations of an array of cpt-city gradient palettes, and
780 | // a count of how many there are. The actual color palette definitions
781 | // are at the bottom of this file.
782 | extern const TProgmemRGBGradientPalettePtr gGradientPalettes[];
783 | extern const uint8_t gGradientPaletteCount;
784 |
785 | // Current palette number from the 'playlist' of color palettes
786 | uint8_t gCurrentPaletteNumber = 0;
787 |
788 | CRGBPalette16 gCurrentPalette( CRGB::Black);
789 | CRGBPalette16 gTargetPalette( gGradientPalettes[0] );
790 |
791 | // ten seconds per color palette makes a good demo
792 | // 20-120 is better for deployment
793 | #define SECONDS_PER_PALETTE 10
794 |
795 | uint16_t colorWaves()
796 | {
797 | EVERY_N_SECONDS( SECONDS_PER_PALETTE ) {
798 | gCurrentPaletteNumber = addmod8( gCurrentPaletteNumber, 1, gGradientPaletteCount);
799 | gTargetPalette = gGradientPalettes[ gCurrentPaletteNumber ];
800 | }
801 |
802 | EVERY_N_MILLISECONDS(40) {
803 | nblendPaletteTowardPalette( gCurrentPalette, gTargetPalette, 16);
804 | }
805 |
806 | colorwaves( leds, NUM_LEDS, gCurrentPalette);
807 |
808 | return 20;
809 | }
810 |
811 |
812 | // This function draws color waves with an ever-changing,
813 | // widely-varying set of parameters, using a color palette.
814 | void colorwaves( CRGB* ledarray, uint16_t numleds, CRGBPalette16& palette)
815 | {
816 | static uint16_t sPseudotime = 0;
817 | static uint16_t sLastMillis = 0;
818 | static uint16_t sHue16 = 0;
819 |
820 | // uint8_t sat8 = beatsin88( 87, 220, 250);
821 | uint8_t brightdepth = beatsin88( 341, 96, 224);
822 | uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
823 | uint8_t msmultiplier = beatsin88(147, 23, 60);
824 |
825 | uint16_t hue16 = sHue16;//gHue * 256;
826 | uint16_t hueinc16 = beatsin88(113, 300, 1500);
827 |
828 | uint16_t ms = millis();
829 | uint16_t deltams = ms - sLastMillis ;
830 | sLastMillis = ms;
831 | sPseudotime += deltams * msmultiplier;
832 | sHue16 += deltams * beatsin88( 400, 5, 9);
833 | uint16_t brightnesstheta16 = sPseudotime;
834 |
835 | for ( uint16_t i = 0 ; i < numleds; i++) {
836 | hue16 += hueinc16;
837 | uint8_t hue8 = hue16 / 256;
838 | uint16_t h16_128 = hue16 >> 7;
839 | if ( h16_128 & 0x100) {
840 | hue8 = 255 - (h16_128 >> 1);
841 | } else {
842 | hue8 = h16_128 >> 1;
843 | }
844 |
845 | brightnesstheta16 += brightnessthetainc16;
846 | uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
847 |
848 | uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
849 | uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
850 | bri8 += (255 - brightdepth);
851 |
852 | uint8_t index = hue8;
853 | //index = triwave8( index);
854 | index = scale8( index, 240);
855 |
856 | CRGB newcolor = ColorFromPalette( palette, index, bri8);
857 |
858 | uint16_t pixelnumber = i;
859 | pixelnumber = (numleds - 1) - pixelnumber;
860 |
861 | nblend( ledarray[pixelnumber], newcolor, 128);
862 | }
863 | }
864 |
865 | // Alternate rendering function just scrolls the current palette
866 | // across the defined LED strip.
867 | void palettetest( CRGB* ledarray, uint16_t numleds, const CRGBPalette16& gCurrentPalette)
868 | {
869 | static uint8_t startindex = 0;
870 | startindex--;
871 | fill_palette( ledarray, numleds, startindex, (256 / NUM_LEDS) + 1, gCurrentPalette, 255, LINEARBLEND);
872 | }
873 |
874 | #define STARTING_BRIGHTNESS 64
875 | #define FADE_IN_SPEED 32
876 | #define FADE_OUT_SPEED 20
877 | uint8_t DENSITY = 255;
878 |
879 | uint16_t cloudTwinkles()
880 | {
881 | DENSITY = 255;
882 | colortwinkles(CloudColors_p);
883 | return 20;
884 | }
885 |
886 | uint16_t rainbowTwinkles()
887 | {
888 | DENSITY = 255;
889 | colortwinkles(RainbowColors_p);
890 | return 20;
891 | }
892 |
893 | uint16_t snowTwinkles()
894 | {
895 | DENSITY = 255;
896 | colortwinkles(snowColors);
897 | return 20;
898 | }
899 |
900 | uint16_t incandescentTwinkles()
901 | {
902 | DENSITY = 255;
903 | colortwinkles(incandescentColors);
904 | return 20;
905 | }
906 |
907 | uint16_t fireflies()
908 | {
909 | DENSITY = 16;
910 | colortwinkles(incandescentColors);
911 | return 20;
912 | }
913 |
914 | enum { GETTING_DARKER = 0, GETTING_BRIGHTER = 1 };
915 |
916 | void colortwinkles(CRGBPalette16 palette)
917 | {
918 | // Make each pixel brighter or darker, depending on
919 | // its 'direction' flag.
920 | brightenOrDarkenEachPixel( FADE_IN_SPEED, FADE_OUT_SPEED);
921 |
922 | // Now consider adding a new random twinkle
923 | if ( random8() < DENSITY ) {
924 | int pos = random16(NUM_LEDS);
925 | if ( !leds[pos]) {
926 | leds[pos] = ColorFromPalette( palette, random8(), STARTING_BRIGHTNESS, NOBLEND);
927 | setPixelDirection(pos, GETTING_BRIGHTER);
928 | }
929 | }
930 | }
931 |
932 | void brightenOrDarkenEachPixel( fract8 fadeUpAmount, fract8 fadeDownAmount)
933 | {
934 | for ( uint16_t i = 0; i < NUM_LEDS; i++) {
935 | if ( getPixelDirection(i) == GETTING_DARKER) {
936 | // This pixel is getting darker
937 | leds[i] = makeDarker( leds[i], fadeDownAmount);
938 | } else {
939 | // This pixel is getting brighter
940 | leds[i] = makeBrighter( leds[i], fadeUpAmount);
941 | // now check to see if we've maxxed out the brightness
942 | if ( leds[i].r == 255 || leds[i].g == 255 || leds[i].b == 255) {
943 | // if so, turn around and start getting darker
944 | setPixelDirection(i, GETTING_DARKER);
945 | }
946 | }
947 | }
948 | }
949 |
950 | CRGB makeBrighter( const CRGB& color, fract8 howMuchBrighter)
951 | {
952 | CRGB incrementalColor = color;
953 | incrementalColor.nscale8( howMuchBrighter);
954 | return color + incrementalColor;
955 | }
956 |
957 | CRGB makeDarker( const CRGB& color, fract8 howMuchDarker)
958 | {
959 | CRGB newcolor = color;
960 | newcolor.nscale8( 255 - howMuchDarker);
961 | return newcolor;
962 | }
963 |
964 | // Compact implementation of
965 | // the directionFlags array, using just one BIT of RAM
966 | // per pixel. This requires a bunch of bit wrangling,
967 | // but conserves precious RAM. The cost is a few
968 | // cycles and about 100 bytes of flash program memory.
969 | uint8_t directionFlags[ (NUM_LEDS + 7) / 8];
970 |
971 | bool getPixelDirection( uint16_t i) {
972 | uint16_t index = i / 8;
973 | uint8_t bitNum = i & 0x07;
974 |
975 | uint8_t andMask = 1 << bitNum;
976 | return (directionFlags[index] & andMask) != 0;
977 | }
978 |
979 | void setPixelDirection( uint16_t i, bool dir) {
980 | uint16_t index = i / 8;
981 | uint8_t bitNum = i & 0x07;
982 |
983 | uint8_t orMask = 1 << bitNum;
984 | uint8_t andMask = 255 - orMask;
985 | uint8_t value = directionFlags[index] & andMask;
986 | if ( dir ) {
987 | value += orMask;
988 | }
989 | directionFlags[index] = value;
990 | }
991 |
--------------------------------------------------------------------------------