forked from slawa19/IKEA-LED-Table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
colorPalette.ino
167 lines (142 loc) · 4.54 KB
/
colorPalette.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
/* LedTable
*
* Written by: Klaas De Craemer, Ing. David Hrbaty
*
* Basic animation with fading stars
*/
#define UPDATES_PER_SECOND 100
CRGBPalette16 currentPalette;
TBlendType currentBlending;
extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
boolean colorPaletteRunning;
// This function fills the palette with totally random colors.
void SetupTotallyRandomPalette()
{
for( int i = 0; i < 16; i++) {
currentPalette[i] = CHSV( random8(), 255, random8());
}
}
// This function sets up a palette of black and white stripes,
// using code. Since the palette is effectively an array of
// sixteen CRGB colors, the various fill_* functions can be used
// to set them up.
void SetupBlackAndWhiteStripedPalette()
{
// 'black out' all 16 palette entries...
fill_solid( currentPalette, 16, CRGB::Black);
// and set every fourth one to white.
currentPalette[0] = CRGB::White;
currentPalette[4] = CRGB::White;
currentPalette[8] = CRGB::White;
currentPalette[12] = CRGB::White;
}
// This function sets up a palette of purple and green stripes.
void SetupPurpleAndGreenPalette()
{
CRGB purple = CHSV( HUE_PURPLE, 255, 255);
CRGB green = CHSV( HUE_GREEN, 255, 255);
CRGB black = CRGB::Black;
currentPalette = CRGBPalette16(
green, green, black, black,
purple, purple, black, black,
green, green, black, black,
purple, purple, black, black );
}
// This example shows how to set up a static color palette
// which is stored in PROGMEM (flash), which is almost always more
// plentiful than RAM. A static PROGMEM palette like this
// takes up 64 bytes of flash.
const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
CRGB::Red,
CRGB::Gray, // 'white' is too bright compared to red and blue
CRGB::Blue,
CRGB::Black,
CRGB::Red,
CRGB::Gray,
CRGB::Blue,
CRGB::Black,
CRGB::Red,
CRGB::Red,
CRGB::Gray,
CRGB::Gray,
CRGB::Blue,
CRGB::Blue,
CRGB::Black,
CRGB::Black
};
void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
uint8_t brightness = 255;
for( int i = 0; i < FIELD_WIDTH * FIELD_HEIGHT; i++) {
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
colorIndex += 3;
}
}
void runColorPalette(){
static uint8_t startIndex = 0;
unsigned long prevUpdateTime = 0;
unsigned long curTime = 0;
colorPaletteRunning = true;
currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND;
clearTablePixels();
showPixels();
while(colorPaletteRunning){
uint8_t secondHand = (millis() / 1000) % 60;
static uint8_t lastSecond = 99;
if( lastSecond != secondHand) {
lastSecond = secondHand;
if( secondHand == 15) { currentPalette = RainbowStripeColors_p; currentBlending = NOBLEND; }
if( secondHand == 30) { SetupBlackAndWhiteStripedPalette(); currentBlending = NOBLEND; }
if( secondHand == 45) { currentPalette = PartyColors_p; currentBlending = LINEARBLEND; }
}
FillLEDsFromPaletteColors( startIndex);
showPixels();
setDelay(1000/UPDATES_PER_SECOND);
startIndex = startIndex + 1;
//Check input keys
do{
readInput();
if (curControl == BTN_EXIT){
colorPaletteRunning = false;
break;
}
curTime = millis();
delay(10);
}
while ((curTime - prevUpdateTime) <20);//Once enough time has passed, proceed. The lower this number, the faster the game is
prevUpdateTime = curTime;
}
}
void runRainbowPalette(){
static uint8_t startIndex = 0;
unsigned long prevUpdateTime = 0;
unsigned long curTime = 0;
colorPaletteRunning = true;
currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND;
clearTablePixels();
showPixels();
while(colorPaletteRunning){
currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND;
FillLEDsFromPaletteColors( startIndex);
showPixels();
setDelay(1000/UPDATES_PER_SECOND);
startIndex = startIndex + 1;
//Check input keys
do{
readInput();
if (curControl == BTN_EXIT){
colorPaletteRunning = false;
break;
}
curTime = millis();
delay(10);
}
while ((curTime - prevUpdateTime) <20);//Once enough time has passed, proceed. The lower this number, the faster the game is
prevUpdateTime = curTime;
}
}