FastLED 3.9.15
Loading...
Searching...
No Matches
BlinkParallel.ino
Go to the documentation of this file.
1// @filter: (memory is large)
2
6
7// FastLED.h must be included first to trigger precompiled headers for FastLED's build system
8#include "FastLED.h"
9
11
12#include "FastLED.h"
13
14// How many leds in your strip?
15#define NUM_LEDS 256
16
17// Demo of driving multiple WS2812 strips on different pins
18
19// Define the array of leds
20CRGB leds[NUM_LEDS]; // Yes, they all share a buffer.
21
22void setup() {
23 Serial.begin(115200);
24 delay(100); // Give serial time to initialize
25
26 delay(2000);
27
28 Serial.println("BlinkParallel setup starting");
29 Serial.print("NUM_LEDS: ");
30 Serial.println(NUM_LEDS);
31
32
33 //FastLED.addLeds<WS2812, 5>(leds, NUM_LEDS); // GRB ordering is assumed
34 FastLED.addLeds<WS2812, 1>(leds, NUM_LEDS); // GRB ordering is assumed
35 FastLED.addLeds<WS2812, 2>(leds, NUM_LEDS); // GRB ordering is assumed
36 FastLED.addLeds<WS2812, 3>(leds, NUM_LEDS); // GRB ordering is assumed
37 FastLED.addLeds<WS2812, 4>(leds, NUM_LEDS); // GRB ordering is assumed
38
39 Serial.print("Initialized 4 LED strips with ");
40 Serial.print(NUM_LEDS);
41 Serial.println(" LEDs each");
42
43 Serial.println("Setup complete - starting blink animation");
44
45 delay(1000);
46}
47
48void fill(CRGB color) {
49 for (int i = 0; i < NUM_LEDS; i++) {
50 leds[i] = color;
51 }
52}
53
54void blink(CRGB color, int times) {
55 for (int i = 0; i < times; i++) {
56 fill(color);
57 FastLED.show();
58 delay(500);
60 FastLED.show();
61 delay(500);
62 }
63}
64
65void loop() {
66 static int loopCount = 0;
67
68 EVERY_N_MILLISECONDS(1000) { // Every 1 second (faster for QEMU testing)
69 loopCount++;
70 Serial.print("Starting loop iteration ");
71 Serial.println(loopCount);
72
73 // Add completion marker after a few loops for QEMU testing
74 if (loopCount >= 2) { // Complete after 2 iterations instead of 3
75 Serial.print("Test finished - completed ");
76 Serial.print(loopCount);
77 Serial.println(" iterations");
78 }
79 }
80
81 // Turn the LED on, then pause
82 blink(CRGB(8,0,0), 1); // blink once for red
83 blink(CRGB(0,8,0), 2); // blink twice for green
84 blink(CRGB(0,0,8), 3); // blink thrice for blue
85
86 delay(50);
87
88 // now benchmark
89 uint32_t start = millis();
90 fill(CRGB(8,8,8));
91 FastLED.show();
92 uint32_t diff = millis() - start;
93
94 Serial.print("Time to fill and show for non blocking (ms): ");
95 Serial.println(diff);
96
97 EVERY_N_MILLISECONDS(500) { // Every 0.5 seconds (faster for QEMU testing)
98 Serial.print("FastLED.show() timing: ");
99 Serial.print(diff);
100 Serial.println("ms");
101 }
102
103 delay(50);
104
105 start = millis();
106 fill(CRGB(8,8,8));
107 FastLED.show();
108 FastLED.show();
109
110 diff = millis() - start;
111 Serial.print("Time to fill and show for 2nd blocking (ms): ");
112 Serial.println(diff);
113}
void setup()
void loop()
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
fl::CRGB CRGB
Definition crgb.h:25
#define EVERY_N_MILLISECONDS(N)
Alias for EVERY_N_MILLIS.
Definition lib8tion.h:1045
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:510
#define Serial
Definition serial.h:304