Skip to content

Commit fa642e2

Browse files
committed
Added palette twinkles.
1 parent 4bbf8f3 commit fa642e2

File tree

5 files changed

+424
-28
lines changed

5 files changed

+424
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Control addressable LEDs with an ESP32 via a web browser over Wi-Fi.
1717
* [x] speed
1818
* [x] palette
1919
* [x] solid color
20+
* [x] twinkle speed/density
2021

2122
### Currently Lacking:
2223
* [ ] Setting storage in EEPROM
2324
* [ ] More patterns
2425
* [ ] More parameters
2526
* [ ] fire cooling/sparking
26-
* [ ] twinkle speed/density
2727

2828
## Requirements
2929

fields.h

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ void setPattern(uint8_t value)
5555

5656
currentPatternIndex = value;
5757

58-
// if (autoplay == 0) {
59-
// EEPROM.write(1, currentPatternIndex);
60-
// EEPROM.commit();
61-
// }
58+
// if (autoplay == 0) {
59+
// EEPROM.write(1, currentPatternIndex);
60+
// EEPROM.commit();
61+
// }
6262

63-
// broadcastInt("pattern", currentPatternIndex);
63+
// broadcastInt("pattern", currentPatternIndex);
6464
}
6565

6666
String setPattern(String value) {
@@ -166,6 +166,32 @@ String setSolidColor(String value) {
166166
return String(solidColor.r) + "," + String(solidColor.g) + "," + String(solidColor.b);
167167
}
168168

169+
String getTwinkleSpeed() {
170+
return String(twinkleSpeed);
171+
}
172+
173+
String setTwinkleSpeed(String value) {
174+
twinkleSpeed = value.toInt();
175+
if (twinkleSpeed < 0) twinkleSpeed = 0;
176+
else if (twinkleSpeed > 8) twinkleSpeed = 8;
177+
// broadcastInt("twinkleSpeed", twinkleSpeed);
178+
// sendInt(twinkleSpeed);
179+
return String(twinkleSpeed);
180+
}
181+
182+
String getTwinkleDensity() {
183+
return String(twinkleDensity);
184+
}
185+
186+
String setTwinkleDensity(String value) {
187+
twinkleDensity = value.toInt();
188+
if (twinkleDensity < 0) twinkleDensity = 0;
189+
else if (twinkleDensity > 8) twinkleDensity = 8;
190+
// broadcastInt("twinkleDensity", twinkleDensity);
191+
// sendInt(twinkleDensity);
192+
return String(twinkleDensity);
193+
}
194+
169195
FieldList fields = {
170196
{ "power", "Power", BooleanFieldType, 0, 1, getPower, NULL, setPower },
171197
{ "brightness", "Brightness", NumberFieldType, 1, 255, getBrightness, NULL, setBrightness },
@@ -177,6 +203,9 @@ FieldList fields = {
177203
{ "autoplayDuration", "Autoplay Duration", NumberFieldType, 0, 255, getAutoplayDuration, NULL, setAutoplayDuration },
178204
{ "solidColorSection", "Solid Color", SectionFieldType },
179205
{ "solidColor", "Color", ColorFieldType, 0, 255, getSolidColor, NULL, setSolidColor },
206+
{ "twinklesSection", "Twinkles", SectionFieldType },
207+
{ "twinkleSpeed", "Twinkle Speed", NumberFieldType, 0, 8, getTwinkleSpeed, NULL, setTwinkleSpeed },
208+
{ "twinkleDensity", "Twinkle Density", NumberFieldType, 0, 8, getTwinkleDensity, NULL, setTwinkleDensity },
180209
};
181210

182211
uint8_t fieldCount = ARRAY_SIZE(fields);

palettes.h

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
ESP32 FastLED WebServer: https://github.com/jasoncoon/esp32-fastled-webserver
3+
Copyright (C) 2017 Jason Coon
4+
5+
Built upon the amazing FastLED work of Daniel Garcia and Mark Kriegsman:
6+
https://github.com/FastLED/FastLED
7+
8+
ESP32 support provided by the hard work of Sam Guyer:
9+
https://github.com/samguyer/FastLED
10+
11+
This program is free software: you can redistribute it and/or modify
12+
it under the terms of the GNU General Public License as published by
13+
the Free Software Foundation, either version 3 of the License, or
14+
(at your option) any later version.
15+
16+
This program is distributed in the hope that it will be useful,
17+
but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
GNU General Public License for more details.
20+
21+
You should have received a copy of the GNU General Public License
22+
along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*/
24+
25+
// A mostly red palette with green accents and white trim.
26+
// "CRGB::Gray" is used as white to keep the brightness more uniform.
27+
const TProgmemRGBPalette16 RedGreenWhite_p FL_PROGMEM =
28+
{ CRGB::Red, CRGB::Red, CRGB::Red, CRGB::Red,
29+
CRGB::Red, CRGB::Red, CRGB::Red, CRGB::Red,
30+
CRGB::Red, CRGB::Red, CRGB::Gray, CRGB::Gray,
31+
CRGB::Green, CRGB::Green, CRGB::Green, CRGB::Green };
32+
33+
// A mostly (dark) green palette with red berries.
34+
#define Holly_Green 0x00580c
35+
#define Holly_Red 0xB00402
36+
const TProgmemRGBPalette16 Holly_p FL_PROGMEM =
37+
{ Holly_Green, Holly_Green, Holly_Green, Holly_Green,
38+
Holly_Green, Holly_Green, Holly_Green, Holly_Green,
39+
Holly_Green, Holly_Green, Holly_Green, Holly_Green,
40+
Holly_Green, Holly_Green, Holly_Green, Holly_Red
41+
};
42+
43+
// A red and white striped palette
44+
// "CRGB::Gray" is used as white to keep the brightness more uniform.
45+
const TProgmemRGBPalette16 RedWhite_p FL_PROGMEM =
46+
{ CRGB::Red, CRGB::Red, CRGB::Gray, CRGB::Gray,
47+
CRGB::Red, CRGB::Red, CRGB::Gray, CRGB::Gray,
48+
CRGB::Red, CRGB::Red, CRGB::Gray, CRGB::Gray,
49+
CRGB::Red, CRGB::Red, CRGB::Gray, CRGB::Gray };
50+
51+
// A mostly blue palette with white accents.
52+
// "CRGB::Gray" is used as white to keep the brightness more uniform.
53+
const TProgmemRGBPalette16 BlueWhite_p FL_PROGMEM =
54+
{ CRGB::Blue, CRGB::Blue, CRGB::Blue, CRGB::Blue,
55+
CRGB::Blue, CRGB::Blue, CRGB::Blue, CRGB::Blue,
56+
CRGB::Blue, CRGB::Blue, CRGB::Blue, CRGB::Blue,
57+
CRGB::Blue, CRGB::Gray, CRGB::Gray, CRGB::Gray };
58+
59+
// A pure "fairy light" palette with some brightness variations
60+
#define HALFFAIRY ((CRGB::FairyLight & 0xFEFEFE) / 2)
61+
#define QUARTERFAIRY ((CRGB::FairyLight & 0xFCFCFC) / 4)
62+
const TProgmemRGBPalette16 FairyLight_p FL_PROGMEM =
63+
{ CRGB::FairyLight, CRGB::FairyLight, CRGB::FairyLight, CRGB::FairyLight,
64+
HALFFAIRY, HALFFAIRY, CRGB::FairyLight, CRGB::FairyLight,
65+
QUARTERFAIRY, QUARTERFAIRY, CRGB::FairyLight, CRGB::FairyLight,
66+
CRGB::FairyLight, CRGB::FairyLight, CRGB::FairyLight, CRGB::FairyLight };
67+
68+
// A palette of soft snowflakes with the occasional bright one
69+
const TProgmemRGBPalette16 Snow_p FL_PROGMEM =
70+
{ 0x304048, 0x304048, 0x304048, 0x304048,
71+
0x304048, 0x304048, 0x304048, 0x304048,
72+
0x304048, 0x304048, 0x304048, 0x304048,
73+
0x304048, 0x304048, 0x304048, 0xE0F0FF };
74+
75+
// A palette reminiscent of large 'old-school' C9-size tree lights
76+
// in the five classic colors: red, orange, green, blue, and white.
77+
#define C9_Red 0xB80400
78+
#define C9_Orange 0x902C02
79+
#define C9_Green 0x046002
80+
#define C9_Blue 0x070758
81+
#define C9_White 0x606820
82+
const TProgmemRGBPalette16 RetroC9_p FL_PROGMEM =
83+
{ C9_Red, C9_Orange, C9_Red, C9_Orange,
84+
C9_Orange, C9_Red, C9_Orange, C9_Red,
85+
C9_Green, C9_Green, C9_Green, C9_Green,
86+
C9_Blue, C9_Blue, C9_Blue,
87+
C9_White
88+
};
89+
90+
// A cold, icy pale blue palette
91+
#define Ice_Blue1 0x0C1040
92+
#define Ice_Blue2 0x182080
93+
#define Ice_Blue3 0x5080C0
94+
const TProgmemRGBPalette16 Ice_p FL_PROGMEM =
95+
{
96+
Ice_Blue1, Ice_Blue1, Ice_Blue1, Ice_Blue1,
97+
Ice_Blue1, Ice_Blue1, Ice_Blue1, Ice_Blue1,
98+
Ice_Blue1, Ice_Blue1, Ice_Blue1, Ice_Blue1,
99+
Ice_Blue2, Ice_Blue2, Ice_Blue2, Ice_Blue3
100+
};
101+
102+
const CRGBPalette16 palettes[] = {
103+
RainbowColors_p,
104+
RainbowStripeColors_p,
105+
CloudColors_p,
106+
LavaColors_p,
107+
OceanColors_p,
108+
ForestColors_p,
109+
PartyColors_p,
110+
HeatColors_p,
111+
Ice_p,
112+
Snow_p,
113+
RedWhite_p,
114+
BlueWhite_p,
115+
FairyLight_p,
116+
RetroC9_p,
117+
RedGreenWhite_p,
118+
Holly_p,
119+
};
120+
121+
const uint8_t paletteCount = ARRAY_SIZE(palettes);
122+
123+
const String paletteNames[paletteCount] = {
124+
"Rainbow",
125+
"Rainbow Stripe",
126+
"Cloud",
127+
"Lava",
128+
"Ocean",
129+
"Forest",
130+
"Party",
131+
"Heat",
132+
"Ice",
133+
"Snow",
134+
"Red & White",
135+
"Blue & White",
136+
"Fairy",
137+
"Retro C9",
138+
"Red, Green & White",
139+
"Holly",
140+
};

patterns.h

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,9 @@
2121
You should have received a copy of the GNU General Public License
2222
along with this program. If not, see <http://www.gnu.org/licenses/>.
2323
*/
24-
const CRGBPalette16 palettes[] = {
25-
RainbowColors_p,
26-
RainbowStripeColors_p,
27-
CloudColors_p,
28-
LavaColors_p,
29-
OceanColors_p,
30-
ForestColors_p,
31-
PartyColors_p,
32-
HeatColors_p
33-
};
3424

35-
const uint8_t paletteCount = ARRAY_SIZE(palettes);
36-
37-
const String paletteNames[paletteCount] = {
38-
"Rainbow",
39-
"Rainbow Stripe",
40-
"Cloud",
41-
"Lava",
42-
"Ocean",
43-
"Forest",
44-
"Party",
45-
"Heat",
46-
};
25+
#include "palettes.h";
26+
#include "twinkleFOX.h"
4727

4828
void rainbow()
4929
{
@@ -122,6 +102,24 @@ typedef struct {
122102
typedef PatternAndName PatternAndNameList[];
123103

124104
PatternAndNameList patterns = {
105+
// TwinkleFOX patterns
106+
{ drawTwinkles, "Twinkles" },
107+
// { retroC9Twinkles, "Retro C9 Twinkles" },
108+
// { redWhiteTwinkles, "Red & White Twinkles" },
109+
// { blueWhiteTwinkles, "Blue & White Twinkles" },
110+
// { redGreenWhiteTwinkles, "Red, Green & White Twinkles" },
111+
// { fairyLightTwinkles, "Fairy Light Twinkles" },
112+
// { snow2Twinkles, "Snow 2 Twinkles" },
113+
// { hollyTwinkles, "Holly Twinkles" },
114+
// { iceTwinkles, "Ice Twinkles" },
115+
// { partyTwinkles, "Party Twinkles" },
116+
// { forestTwinkles, "Forest Twinkles" },
117+
// { lavaTwinkles, "Lava Twinkles" },
118+
// { fireTwinkles, "Fire Twinkles" },
119+
// { cloud2Twinkles, "Cloud 2 Twinkles" },
120+
// { oceanTwinkles, "Ocean Twinkles" },
121+
122+
// DemoReel100 patterns
125123
{ rainbow, "rainbow" },
126124
{ rainbowWithGlitter, "rainbowWithGlitter" },
127125
{ confetti, "confetti" },

0 commit comments

Comments
 (0)