28
28
#include < FS.h>
29
29
#include < SPIFFS.h>
30
30
31
+ #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001008)
32
+ #warning "Requires FastLED 3.1.8 or later; check github for latest code."
33
+ #endif
34
+
31
35
WebServer webServer (80 );
32
36
33
37
const int led = 5 ;
@@ -37,52 +41,15 @@ uint8_t autoplayDuration = 10;
37
41
unsigned long autoPlayTimeout = 0 ;
38
42
39
43
uint8_t currentPatternIndex = 0 ; // Index number of which pattern is current
44
+ uint8_t currentPaletteIndex = 0 ;
40
45
uint8_t gHue = 0 ; // rotating "base color" used by many of the patterns
41
46
42
- const uint8_t brightnessCount = 5 ;
43
- uint8_t brightnessMap[brightnessCount] = { 16 , 32 , 64 , 128 , 255 };
44
- uint8_t brightnessIndex = 0 ;
45
47
uint8_t power = 1 ;
46
- uint8_t brightness = brightnessMap[brightnessIndex];
47
-
48
- #define ARRAY_SIZE (A ) (sizeof (A) / sizeof ((A)[0 ]))
48
+ uint8_t brightness = 64 ;
49
49
50
- typedef void (*Pattern)();
51
- typedef Pattern PatternList[];
52
- typedef struct {
53
- Pattern pattern;
54
- String name;
55
- } PatternAndName;
56
- typedef PatternAndName PatternAndNameList[];
57
-
58
- void rainbow ();
59
- void rainbowWithGlitter ();
60
- void confetti ();
61
- void sinelon ();
62
- void juggle ();
63
- void bpm ();
64
-
65
- PatternAndNameList patterns = {
66
- { rainbow, " rainbow" },
67
- { rainbowWithGlitter, " rainbowWithGlitter" },
68
- { confetti, " confetti" },
69
- { sinelon, " sinelon" },
70
- { juggle, " juggle" },
71
- { bpm, " bpm" },
72
- };
73
-
74
- const uint8_t patternCount = ARRAY_SIZE(patterns);
50
+ uint8_t speed = 30 ;
75
51
76
- #include " field.h"
77
- #include " fields.h"
78
-
79
- #include " secrets.h"
80
- #include " wifi.h"
81
- #include " web.h"
82
-
83
- #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001008)
84
- #warning "Requires FastLED 3.1.8 or later; check github for latest code."
85
- #endif
52
+ #define ARRAY_SIZE (A ) (sizeof (A) / sizeof ((A)[0 ]))
86
53
87
54
#define DATA_PIN 12
88
55
// #define CLK_PIN 4
@@ -91,12 +58,20 @@ const uint8_t patternCount = ARRAY_SIZE(patterns);
91
58
#define NUM_LEDS 14
92
59
CRGB leds[NUM_LEDS];
93
60
94
- #define BRIGHTNESS 60
95
61
#define FRAMES_PER_SECOND 120
96
62
97
63
// -- The core to run FastLED.show()
98
64
#define FASTLED_SHOW_CORE 0
99
65
66
+ #include " patterns.h"
67
+
68
+ #include " field.h"
69
+ #include " fields.h"
70
+
71
+ #include " secrets.h"
72
+ #include " wifi.h"
73
+ #include " web.h"
74
+
100
75
// wifi ssid and password should be added to a file in the sketch named secrets.h
101
76
// the secrets.h file should be added to the .gitignore file and never committed or
102
77
// pushed to public source control (GitHub).
@@ -196,7 +171,7 @@ void setup() {
196
171
// FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
197
172
198
173
// set master brightness control
199
- FastLED.setBrightness (BRIGHTNESS );
174
+ FastLED.setBrightness (brightness );
200
175
201
176
int core = xPortGetCoreID ();
202
177
Serial.print (" Main code running on core " );
@@ -244,60 +219,5 @@ void nextPattern()
244
219
currentPatternIndex = (currentPatternIndex + 1 ) % ARRAY_SIZE ( patterns);
245
220
}
246
221
247
- void rainbow ()
248
- {
249
- // FastLED's built-in rainbow generator
250
- fill_rainbow ( leds, NUM_LEDS, gHue , 7 );
251
- }
252
-
253
- void rainbowWithGlitter ()
254
- {
255
- // built-in FastLED rainbow, plus some random sparkly glitter
256
- rainbow ();
257
- addGlitter (80 );
258
- }
259
-
260
- void addGlitter ( fract8 chanceOfGlitter)
261
- {
262
- if ( random8 () < chanceOfGlitter) {
263
- leds[ random16 (NUM_LEDS) ] += CRGB::White;
264
- }
265
- }
266
222
267
- void confetti ()
268
- {
269
- // random colored speckles that blink in and fade smoothly
270
- fadeToBlackBy ( leds, NUM_LEDS, 10 );
271
- int pos = random16 (NUM_LEDS);
272
- leds[pos] += CHSV ( gHue + random8 (64 ), 200 , 255 );
273
- }
274
-
275
- void sinelon ()
276
- {
277
- // a colored dot sweeping back and forth, with fading trails
278
- fadeToBlackBy ( leds, NUM_LEDS, 20 );
279
- int pos = beatsin16 ( 13 , 0 , NUM_LEDS - 1 );
280
- leds[pos] += CHSV ( gHue , 255 , 192 );
281
- }
282
-
283
- void bpm ()
284
- {
285
- // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
286
- uint8_t BeatsPerMinute = 62 ;
287
- CRGBPalette16 palette = PartyColors_p;
288
- uint8_t beat = beatsin8 ( BeatsPerMinute, 64 , 255 );
289
- for ( int i = 0 ; i < NUM_LEDS; i++) { // 9948
290
- leds[i] = ColorFromPalette (palette, gHue + (i * 2 ), beat - gHue + (i * 10 ));
291
- }
292
- }
293
-
294
- void juggle () {
295
- // eight colored dots, weaving in and out of sync with each other
296
- fadeToBlackBy ( leds, NUM_LEDS, 20 );
297
- byte dothue = 0 ;
298
- for ( int i = 0 ; i < 8 ; i++) {
299
- leds[beatsin16 ( i + 7 , 0 , NUM_LEDS - 1 )] |= CHSV (dothue, 200 , 255 );
300
- dothue += 32 ;
301
- }
302
- }
303
223
0 commit comments