-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathmatching_glitter.ino
132 lines (101 loc) · 3.75 KB
/
matching_glitter.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
//***************************************************************
// This example fills the strip with a dim desaturated color and
// then, similar to the "addGlitter" funtion in the DemoReel100
// example, random pixels are sparkled, but instead of brighten
// to white, it brightens the pixel's current color.
//
// See this example for the original mentioned "addGlitter" effect.
// https://github.com/FastLED/FastLED/blob/master/examples/DemoReel100/DemoReel100.ino
//
//
// Marc Miller, Jan 2022
//***************************************************************
#include "FastLED.h"
#define LED_TYPE LPD8806
#define DATA_PIN 11
#define CLOCK_PIN 13
#define COLOR_ORDER GRB
#define BRIGHTNESS 128
#define NUM_LEDS 32
CRGB leds[NUM_LEDS];
uint8_t hue;
//---------------------------------------------------------------
void setup() {
Serial.begin(115200);
delay(3000); // Startup delay
FastLED.addLeds<LED_TYPE, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
//FastLED.addLeds<LED_TYPE, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness(BRIGHTNESS);
Serial.println("Setup done.\n\n");
}
//---------------------------------------------------------------
void loop() {
EVERY_N_MILLISECONDS(20) {
hue++; // slowly cycle around the color wheel
}
EVERY_N_MILLISECONDS(80) {
fill_solid(leds, NUM_LEDS, CHSV(hue, 175, 140) );
// A few different things to try out.
// Un-comment one of these at a time.
//addGlitter(99); // white, the same as in DemoReel100 example
addMatchingGlitter(99);
//addMatchingGlitter_2(99);
//addMatchingGlitter_3(99);
//addMatchingGlitter_4(99);
}
FastLED.show();
}//end_main_loop
//---------------------------------------------------------------
void addMatchingGlitter( fract8 chanceOfGlitter)
// If you know the current hue, it's super easy to simply
// do something like this:
{
if( random8() < chanceOfGlitter) {
leds[ random16(NUM_LEDS) ] += CHSV(hue,255,255);
}
}
//---------------------------------------------------------------
void addMatchingGlitter_2( fract8 chanceOfGlitter)
{
if( random8() < chanceOfGlitter) {
leds[ random16(NUM_LEDS) ].maximizeBrightness(255);
}
}
//---------------------------------------------------------------
void addMatchingGlitter_3( fract8 chanceOfGlitter)
{
if( random8() < chanceOfGlitter) {
uint16_t i = random16(NUM_LEDS);
CRGB color = leds[i];
leds[i] += color.nscale8_video(255);
// Can apply a second or third time for even brighter effect
//leds[i] += color.nscale8_video(255);
//leds[i] += color.nscale8_video(255);
}
}
//---------------------------------------------------------------
void addMatchingGlitter_4( fract8 chanceOfGlitter)
{
if( random8() < chanceOfGlitter) {
uint16_t i = random16(NUM_LEDS);
leds[i].r = brighten8_video(leds[i].r);
leds[i].g = brighten8_video(leds[i].g);
leds[i].b = brighten8_video(leds[i].b);
// Can apply a second time for even brigter effect
//leds[i].r = brighten8_video(leds[i].r);
//leds[i].g = brighten8_video(leds[i].g);
//leds[i].b = brighten8_video(leds[i].b);
}
}
//---------------------------------------------------------------
void addGlitter( fract8 chanceOfGlitter)
// Copied from DemoReel100 example for reference.
// Adds bright white glitter.
{
if( random8() < chanceOfGlitter) {
leds[ random16(NUM_LEDS) ] += CRGB::White;
}
}
//---------------------------------------------------------------
// Also perhaps useful, see this section of the wiki:
// https://github.com/FastLED/FastLED/wiki/Pixel-reference#dimming-and-brightening-colors