@@ -35,6 +35,47 @@ extern const TProgmemPalette16 IRAM_ATTR myRedWhiteBluePalette_p;
3535CRGB leds1[NUM_LEDS];
3636CRGB leds2[NUM_LEDS];
3737
38+ #define N_COLORS 17
39+ static const CRGB colors[N_COLORS] = {
40+ CRGB::Red,
41+ CRGB::Green,
42+ CRGB::Blue,
43+ CRGB::White,
44+ CRGB::AliceBlue,
45+ CRGB::ForestGreen,
46+ CRGB::Lavender,
47+ CRGB::MistyRose,
48+ CRGB::DarkOrchid,
49+ CRGB::DarkOrange,
50+ CRGB::Black,
51+ CRGB::Teal,
52+ CRGB::Violet,
53+ CRGB::Lime,
54+ CRGB::Chartreuse,
55+ CRGB::BlueViolet,
56+ CRGB::Aqua
57+ };
58+
59+ static const char *colors_names[N_COLORS] {
60+ " Red" ,
61+ " Green" ,
62+ " Blue" ,
63+ " White" ,
64+ " aliceblue" ,
65+ " ForestGreen" ,
66+ " Lavender" ,
67+ " MistyRose" ,
68+ " DarkOrchid" ,
69+ " DarkOrange" ,
70+ " Black" ,
71+ " Teal" ,
72+ " Violet" ,
73+ " Lime" ,
74+ " Chartreuse" ,
75+ " BlueViolet" ,
76+ " Aqua"
77+ };
78+
3879extern " C" {
3980 void app_main ();
4081}
@@ -43,7 +84,7 @@ extern "C" {
4384**
4485*/
4586
46- static void blinkWithFx (void *pvParameters) {
87+ static void blinkWithFx_allpatterns (void *pvParameters) {
4788
4889 uint16_t mode = FX_MODE_STATIC;
4990
@@ -72,7 +113,135 @@ static void blinkWithFx(void *pvParameters) {
72113 }
73114};
74115
116+ /* test specific patterns so we know FX is working right
117+ **
118+ */
119+
120+ typedef struct {
121+ const char *name;
122+ int mode;
123+ int secs; // secs to test it
124+ uint32_t color;
125+ int speed;
126+ } testModes_t;
127+
128+
129+ static const testModes_t testModes[] = {
130+ { " color wipe: all leds after each other up. Then off. Repeat. RED" , FX_MODE_COLOR_WIPE, 5 , 0xFF0000 , 1000 },
131+ { " color wipe: all leds after each other up. Then off. Repeat. RGREE" , FX_MODE_COLOR_WIPE, 5 , 0x00FF00 , 1000 },
132+ { " color wipe: all leds after each other up. Then off. Repeat. Blu" , FX_MODE_COLOR_WIPE, 5 , 0x0000FF , 1000 },
133+ { " chase rainbow: Color running on white." , FX_MODE_CHASE_RAINBOW, 10 , 0xffffff , 200 },
134+ { " breath, on white." , FX_MODE_BREATH, 5 , 0xffffff , 100 },
135+ { " breath, on red." , FX_MODE_BREATH, 5 , 0xff0000 , 100 },
136+ { " what is twinkefox? on red?" , FX_MODE_TWINKLEFOX, 20 , 0xff0000 , 2000 },
137+ };
138+
139+ #define TEST_MODES_N ( sizeof (testModes) / sizeof (testModes_t))
140+
141+ static void blinkWithFx_test (void *pvParameters) {
142+
143+ WS2812FX ws2812fx;
144+ WS2812FX::Segment *segments = ws2812fx.getSegments ();
145+
146+ ws2812fx.init (NUM_LEDS, leds1, false ); // type was configured before
147+ ws2812fx.setBrightness (255 );
148+
149+ int test_id = 0 ;
150+ printf (" start mode: %s\n " ,testModes[test_id].name );
151+ ws2812fx.setMode (0 /* segid*/ , testModes[test_id].mode );
152+ segments[0 ].colors [0 ] = testModes[test_id].color ;
153+ segments[0 ].speed = testModes[test_id].speed ;
154+ uint64_t nextMode = esp_timer_get_time () + (testModes[test_id].secs * 1000000L );
155+
75156
157+ while (true ) {
158+
159+ uint64_t now = esp_timer_get_time ();
160+
161+ if (nextMode < now ) {
162+ test_id = (test_id +1 ) % TEST_MODES_N;
163+ nextMode = esp_timer_get_time () + (testModes[test_id].secs * 1000000L );
164+ ws2812fx.setMode (0 /* segid*/ , testModes[test_id].mode );
165+ segments[0 ].colors [0 ] = testModes[test_id].color ;
166+ segments[0 ].speed = testModes[test_id].speed ;
167+ printf (" changed mode to: %s\n " ,testModes[test_id].name );
168+ }
169+
170+ ws2812fx.service ();
171+ vTaskDelay (10 / portTICK_PERIOD_MS); /* 10ms*/
172+ }
173+ };
174+
175+
176+ /*
177+ ** chase sequences are good for testing correctness, because you can see
178+ ** that the colors are correct, and you can see cases where the wrong pixel is lit.
179+ */
180+
181+ #define CHASE_DELAY 200
182+
183+ void blinkLeds_chase2 (void *pvParameters) {
184+
185+ while (true ) {
186+
187+ for (int ci = 0 ; ci < N_COLORS; ci++) {
188+ CRGB color = colors[ci];
189+ printf (" chase: *** color %s ***\n " ,colors_names[ci]);
190+
191+ // set strings to black first
192+ fill_solid (leds1, NUM_LEDS, CRGB::Black);
193+ fill_solid (leds2, NUM_LEDS, CRGB::Black);
194+ FastLED.show ();
195+
196+ int prev;
197+
198+ // forward
199+ printf (" chase: forward\n " );
200+ prev = -1 ;
201+ for (int i = 0 ; i < NUM_LEDS; i++) {
202+ if (prev >= 0 ) {
203+ leds2[prev] = leds1[prev] = CRGB::Black;
204+ }
205+ leds2[i] = leds1[i] = color;
206+ prev = i;
207+
208+ FastLED.show ();
209+ delay (CHASE_DELAY);
210+ }
211+
212+ printf (" chase: backward\n " );
213+ prev = -1 ;
214+ for (int i = NUM_LEDS-1 ; i >= 0 ; i--) {
215+ if (prev >= 0 ) {
216+ leds2[prev] = leds1[prev] = CRGB::Black;
217+ }
218+ leds2[i] = leds1[i] = color;
219+ prev = i;
220+
221+ FastLED.show ();
222+ delay (CHASE_DELAY);
223+ }
224+
225+ // two at a time
226+ printf (" chase: twofer\n " );
227+ prev = -1 ;
228+ for (int i = 0 ; i < NUM_LEDS; i += 2 ) {
229+ if (prev >= 0 ) {
230+ leds2[prev] = leds1[prev] = CRGB::Black;
231+ leds2[prev+1 ] = leds1[prev+1 ] = CRGB::Black;
232+ }
233+ leds2[i] = leds1[i] = color;
234+ leds2[i+1 ] = leds1[i+1 ] = color;
235+ prev = i;
236+
237+ FastLED.show ();
238+ delay (CHASE_DELAY);
239+ }
240+
241+ } // for all colors
242+ } // while true
243+
244+ }
76245
77246void ChangePalettePeriodically (){
78247
@@ -173,26 +342,7 @@ static void fastfade(void *pvParameters){
173342
174343}
175344
176- #define N_COLORS 17
177- CRGB colors[N_COLORS] = {
178- CRGB::AliceBlue,
179- CRGB::ForestGreen,
180- CRGB::Lavender,
181- CRGB::MistyRose,
182- CRGB::DarkOrchid,
183- CRGB::DarkOrange,
184- CRGB::Black,
185- CRGB::Red,
186- CRGB::Green,
187- CRGB::Blue,
188- CRGB::White,
189- CRGB::Teal,
190- CRGB::Violet,
191- CRGB::Lime,
192- CRGB::Chartreuse,
193- CRGB::BlueViolet,
194- CRGB::Aqua
195- };
345+
196346
197347void blinkLeds_simple (void *pvParameters){
198348
@@ -269,6 +419,9 @@ void app_main() {
269419 printf (" create task for led blinking\n " );
270420
271421 // xTaskCreatePinnedToCore(&blinkLeds_simple, "blinkLeds", 4000, NULL, 5, NULL, 0);
272- xTaskCreatePinnedToCore (&fastfade, " blinkLeds" , 4000 , NULL , 5 , NULL , 0 );
273- // xTaskCreatePinnedToCore(&blinkWithFx, "blinkLeds", 4000, NULL, 5, NULL, 0);
422+ // xTaskCreatePinnedToCore(&fastfade, "blinkLeds", 4000, NULL, 5, NULL, 0);
423+ // xTaskCreatePinnedToCore(&blinkWithFx_allpatterns, "blinkLeds", 4000, NULL, 5, NULL, 0);
424+ xTaskCreatePinnedToCore (&blinkWithFx_test, " blinkLeds" , 4000 , NULL , 5 , NULL , 0 );
425+ // xTaskCreatePinnedToCore(&blinkLeds_chase, "blinkLeds", 4000, NULL, 5, NULL, 0);
426+ // xTaskCreatePinnedToCore(&blinkLeds_chase2, "blinkLeds", 4000, NULL, 5, NULL, 0);
274427}
0 commit comments