-
Notifications
You must be signed in to change notification settings - Fork 46
/
DemoReel100_RandomShiftedGlitter.ino
133 lines (111 loc) · 5.12 KB
/
DemoReel100_RandomShiftedGlitter.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
//***************************************************************
// Two rainbow glitter patterns with color glitter instead of
// white glitter. One picks random colors, the other slightly
// shifts the hue of whatever pixel is randomly selected.
//
// These can be added to Mark Kriegsman's DemoReel100 example as
// additional patterns to run. Copy lines 25 and 26 as well
// as the two patterns below to your DemoReel100 program.
//
// Marc Miller, Oct 2016
//***************************************************************
#include "FastLED.h"
FASTLED_USING_NAMESPACE
#define DATA_PIN 11
#define CLK_PIN 13
#define LED_TYPE APA102
#define COLOR_ORDER BGR
#define NUM_LEDS 38
#define BRIGHTNESS 96
#define FRAMES_PER_SECOND 120
CRGB leds[NUM_LEDS];
uint16_t ledsData[NUM_LEDS][4]; // array to store RGB 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 = { rainbowShiftedGlitter, rainbowRandomGlitter };
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_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
EVERY_N_SECONDS( 10 ) { 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 rainbowRandomGlitter() {
fill_rainbow( leds, NUM_LEDS, gHue, 7);
if( random8() < 45 ) { // How often to glitter things up! Higher number is more often.
pick = random16(NUM_LEDS);
if (ledsData[pick][3] == 0 ) {
ledsData[pick][3] = 40; // Used to tag pixel and determine glitter time
ledsData[pick][0] = random8(); // Pick random rgb values
ledsData[pick][1] = random8();
ledsData[pick][2] = random8();
}
}
for (uint16_t i=0; i < NUM_LEDS; i++) {
if (ledsData[i][3] == 0) {
leds[i].fadeToBlackBy(180); // Fade down non-glittering pixels so glitter will show up more
} else {
//leds[i] = CRGB(ledsData[i][0], ledsData[i][1], ledsData[i][2]); // Plug in rgb values
leds[i].fadeToBlackBy(8); // Slowly fade down
ledsData[i][0] = leds[i].r; // Store the rgb values back in ledsData array
ledsData[i][1] = leds[i].g;
ledsData[i][2] = leds[i].b;
ledsData[i][3] = ledsData[i][3] - 1;
}
}
}//end rainbowRandomGlitter
//---------------------------------------------------------------
void rainbowShiftedGlitter() {
fill_rainbow( leds, NUM_LEDS, gHue, 3);
if( random8() < 30 ) { // How often to glitter things up! Higher number is more often.
pick = random16(NUM_LEDS);
if (ledsData[pick][3] == 0 ) {
ledsData[pick][3] = 35; // Used to tag pixel and determine glitter time
CRGB rgb(leds[pick].r, leds[pick].g, leds[pick].b);
CHSV hsv = rgb2hsv_approximate(rgb); // Used to get approx Hue
leds[pick] = CHSV(hsv.hue-50, 255, 255); // Color shift Hue on glitter pixel
ledsData[pick][0] = leds[pick].r; // Store rgb values back in ledsData array
ledsData[pick][1] = leds[pick].g;
ledsData[pick][2] = leds[pick].b;
}
}
for (uint16_t i=0; i < NUM_LEDS; i++) {
if (ledsData[i][3] == 0) {
leds[i].fadeToBlackBy(180); // Fade down non-glittering pixels so glitter will show up more
} else {
leds[i] = CRGB(ledsData[i][0], ledsData[i][1], ledsData[i][2]); // Plug in rgb values
leds[i].fadeToBlackBy(7); // Slowly fade down
ledsData[i][0] = leds[i].r; // Store the rgb values back in ledsData array
ledsData[i][1] = leds[i].g;
ledsData[i][2] = leds[i].b;
ledsData[i][3] = ledsData[i][3] - 1;
}
}
}//end rainbowShiftedGlitter
//---------------------------------------------------------------