-
Notifications
You must be signed in to change notification settings - Fork 46
/
DemoReel100_ChristmasSparkles.ino
212 lines (185 loc) · 8.36 KB
/
DemoReel100_ChristmasSparkles.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//***************************************************************
// Random sparkle patterns with Christmas-ish colors.
// Patterns: christmasSparkles, christmasSparklesRB, christmasSparklesBP
//
// This can be added to Mark Kriegsman's DemoReel100 as new patterns to run.
// Copy lines 25 and 26 as well as the patterns below to your program.
//
// Marc Miller, Dec 2016
//***************************************************************
#include "FastLED.h"
FASTLED_USING_NAMESPACE
#define DATA_PIN 11
#define CLK_PIN 13
#define LED_TYPE LPD8806
#define COLOR_ORDER GRB
#define NUM_LEDS 32
#define BRIGHTNESS 255
#define FRAMES_PER_SECOND 120
CRGB leds[NUM_LEDS];
uint16_t ledsData[NUM_LEDS][4]; // array to store color data and an extra value
uint16_t pick; // stores a temporary pixel number
//---------------------------------------------------------------
void setup() {
Serial.begin(115200); // Allows serial monitor output (check baud rate)
delay(3000); // 3 second delay for recovery
//FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}
//---------------------------------------------------------------
// List of patterns to cycle through. Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { christmasSparkles, christmasSparklesRG, christmasSparkles, christmasSparklesBP };
uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
//---------------------------------------------------------------
void loop() {
// Call the current pattern function once, updating the 'leds' array
gPatterns[gCurrentPatternNumber]();
//FastLED.show();
FastLED.delay(1000/FRAMES_PER_SECOND); // slows the framerate to a modest value
// do some periodic updates
EVERY_N_SECONDS( 20 ) { nextPattern(); } // change patterns periodically
}
//---------------------------------------------------------------
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
void nextPattern()
{
// add one to the current pattern number, and wrap around at the end
gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}
//===============================================================
// The different patterns to choose from...
//===============================================================
//---------------------------------------------------------------
void christmasSparkles() {
//"Background" color for non-sparkling pixels.
CRGB sparkleBgColor = CHSV(50, 30, 40); // dim white
//CRGB sparkleBgColor = CHSV(96, 200, 30); // dim green
EVERY_N_MILLISECONDS(40){
if( random8() < 60 ) { // How much to sparkle! Higher number is more.
pick = random16(NUM_LEDS);
if (ledsData[pick][3] == 0 ) {
ledsData[pick][3] = 35; // Used to tag pixel as sparkling
uint8_t randomPick = random8(5);
if (randomPick == 0) {
ledsData[pick][0] = 178; // sparkle hue (blue)
ledsData[pick][1] = 244; // sparkle saturation
ledsData[pick][2] = 210; // sparkle value
}
if (randomPick == 1) {
ledsData[pick][0] = 10; // sparkle hue (red)
ledsData[pick][1] = 255; // sparkle saturation
ledsData[pick][2] = 240; // sparkle value
}
if (randomPick == 2) {
ledsData[pick][0] = 0; // sparkle hue (white-ish)
ledsData[pick][1] = 25; // sparkle saturation
ledsData[pick][2] = 255; // sparkle value
}
if (randomPick == 3) {
ledsData[pick][0] = 35; // sparkle hue (orange)
ledsData[pick][1] = 235; // sparkle saturation
ledsData[pick][2] = 245; // sparkle value
}
if (randomPick == 4) {
ledsData[pick][0] = 190; // sparkle hue (purple)
ledsData[pick][1] = 255; // sparkle saturation
ledsData[pick][2] = 238; // sparkle value
}
leds[pick] = CHSV(ledsData[pick][0], ledsData[pick][1], ledsData[pick][2]);
}
}
for (uint16_t i=0; i < NUM_LEDS; i++) {
if (ledsData[i][3] == 0) { // if not sparkling, set to "back ground" color
leds[i] = sparkleBgColor;
} else {
CHSV hsv = rgb2hsv_approximate(leds[i]); // Used to get approximate Hue
EVERY_N_MILLISECONDS(38) { ledsData[i][0] = hsv.hue - 1; } // slightly shift hue
ledsData[i][2] = scale8(ledsData[i][2], 245); // slowly darken
leds[i] = CHSV(ledsData[i][0], ledsData[i][1], ledsData[i][2]);
ledsData[i][3] = ledsData[i][3] - 1; // countdown sparkle tag
}
}
}
}//end christmasSparkles
//---------------------------------------------------------------
void christmasSparklesRG() { // Red and Green only
//"Background" color for non-sparkling pixels. Can be set to black for no bg color.
CRGB sparkleBgColor = CHSV(0, 0, 0); // black
//CRGB sparkleBgColor = CHSV(50, 30, 30); // dim white
EVERY_N_MILLISECONDS(40){
if( random8() < 110 ) { // How much to sparkle! Higher number is more.
pick = random16(NUM_LEDS);
if (ledsData[pick][3] == 0 ) {
ledsData[pick][3] = 65; // Used to tag pixel as sparkling
uint8_t randomPick = random8(2);
if (randomPick == 0) {
ledsData[pick][0] = 16; // sparkle hue (red)
ledsData[pick][1] = 253; // sparkle saturation
ledsData[pick][2] = 242; // sparkle value
}
if (randomPick == 1) {
ledsData[pick][0] = 96; // sparkle hue (green)
ledsData[pick][1] = 230; // sparkle saturation
ledsData[pick][2] = 255; // sparkle value
}
leds[pick] = CHSV(ledsData[pick][0], ledsData[pick][1], ledsData[pick][2]);
}
}
for (uint16_t i=0; i < NUM_LEDS; i++) {
if (ledsData[i][3] == 0) { // if not sparkling, set to "back ground" color
leds[i] = sparkleBgColor;
} else {
CHSV hsv = rgb2hsv_approximate(leds[i]); // Used to get approximate Hue
EVERY_N_MILLISECONDS(50) { ledsData[i][0] = hsv.hue - 1; } // slightly shift hue
ledsData[i][2] = scale8(ledsData[i][2], 253); // slowly darken
leds[i] = CHSV(ledsData[i][0], ledsData[i][1], ledsData[i][2]);
ledsData[i][3] = ledsData[i][3] - 1; // countdown sparkle tag
}
}
}
}//end christmasSparklesRG
//---------------------------------------------------------------
void christmasSparklesBP() { // Blues and Purple only
//"Background" color for non-sparkling pixels.
CRGB sparkleBgColor = CHSV(96, 185, 30); // green
EVERY_N_MILLISECONDS(40){
if( random8() < 170 ) { // How much to sparkle! Higher number is more.
pick = random16(NUM_LEDS);
if (ledsData[pick][3] == 0 ) {
ledsData[pick][3] = 20; // Used to tag pixel as sparkling
uint8_t randomPick = random8(3);
if (randomPick == 0) {
ledsData[pick][0] = 165; // sparkle hue (blue)
ledsData[pick][1] = 180; // sparkle saturation
ledsData[pick][2] = 230; // sparkle value
}
if (randomPick == 1) {
ledsData[pick][0] = 200; // sparkle hue (pink-light-purple)
ledsData[pick][1] = 170; // sparkle saturation
ledsData[pick][2] = 240; // sparkle value
}
if (randomPick == 2) {
ledsData[pick][0] = 130; // sparkle hue (light blue)
ledsData[pick][1] = 200; // sparkle saturation
ledsData[pick][2] = 255; // sparkle value
}
leds[pick] = CHSV(ledsData[pick][0], ledsData[pick][1], ledsData[pick][2]);
}
}
for (uint16_t i=0; i < NUM_LEDS; i++) {
if (ledsData[i][3] == 0) { // if not sparkling, set to "back ground" color
leds[i] = sparkleBgColor;
} else {
CHSV hsv = rgb2hsv_approximate(leds[i]); // Used to get approximate Hue
EVERY_N_MILLISECONDS(20) { ledsData[i][0] = hsv.hue - 1; } // slightly shift hue
ledsData[i][2] = scale8(ledsData[i][2], 242); // slowly darken
leds[i] = CHSV(ledsData[i][0], ledsData[i][1], ledsData[i][2]);
ledsData[i][3] = ledsData[i][3] - 1; // countdown sparkle tag
}
}
}
}//end christmasSparklesBP
//---------------------------------------------------------------