FastLED 3.9.15
Loading...
Searching...
No Matches
BlinkParallel.ino
Go to the documentation of this file.
1
5
6#include "FastLED.h"
7
8
9#if SKETCH_HAS_LOTS_OF_MEMORY
10// How many leds in your strip?
11#define NUM_LEDS 256
12#else
13#define NUM_LEDS 16
14#endif
15
16// Demo of driving multiple WS2812 strips on different pins
17
18// Define the array of leds
19CRGB leds[NUM_LEDS]; // Yes, they all share a buffer.
20
21void setup() {
22 Serial.begin(115200);
23
24 //FastLED.addLeds<WS2812, 5>(leds, NUM_LEDS); // GRB ordering is assumed
25 FastLED.addLeds<WS2812, 1>(leds, NUM_LEDS); // GRB ordering is assumed
26 FastLED.addLeds<WS2812, 2>(leds, NUM_LEDS); // GRB ordering is assumed
27 FastLED.addLeds<WS2812, 3>(leds, NUM_LEDS); // GRB ordering is assumed
28 FastLED.addLeds<WS2812, 4>(leds, NUM_LEDS); // GRB ordering is assumed
29
30 FL_WARN("Initialized 4 LED strips with " << NUM_LEDS << " LEDs each");
31 FL_WARN("Setup complete - starting blink animation");
32
33 delay(1000);
34}
35
36void fill(CRGB color) {
37 for (int i = 0; i < NUM_LEDS; i++) {
38 leds[i] = color;
39 }
40}
41
42void blink(CRGB color, int times) {
43 for (int i = 0; i < times; i++) {
44 fill(color);
45 FastLED.show();
46 delay(500);
48 FastLED.show();
49 delay(500);
50 }
51}
52
53void loop() {
54 static int loopCount = 0;
55
56 EVERY_N_MILLISECONDS(1000) { // Every 1 second (faster for QEMU testing)
57 loopCount++;
58 FL_WARN("Starting loop iteration " << loopCount);
59
60 // Add completion marker after a few loops for QEMU testing
61 if (loopCount >= 2) { // Complete after 2 iterations instead of 3
62 FL_WARN("FL_WARN test finished - completed " << loopCount << " iterations");
63 }
64 }
65
66 // Turn the LED on, then pause
67 blink(CRGB(8,0,0), 1); // blink once for red
68 blink(CRGB(0,8,0), 2); // blink twice for green
69 blink(CRGB(0,0,8), 3); // blink thrice for blue
70
71 delay(50);
72
73 // now benchmark
74 uint32_t start = millis();
75 fill(CRGB(8,8,8));
76 FastLED.show();
77 uint32_t diff = millis() - start;
78
79 Serial.print("Time to fill and show for non blocking (ms): ");
80 Serial.println(diff);
81
82 EVERY_N_MILLISECONDS(500) { // Every 0.5 seconds (faster for QEMU testing)
83 FL_WARN("FastLED.show() timing: " << diff << "ms");
84 }
85
86 delay(50);
87
88 start = millis();
89 fill(CRGB(8,8,8));
90 FastLED.show();
91 FastLED.show();
92
93 diff = millis() - start;
94 Serial.print("Time to fill and show for 2nd blocking (ms): ");
95 Serial.println(diff);
96}
CRGB leds[NUM_LEDS]
#define NUM_LEDS
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:74
central include file for FastLED, defines the CFastLED class/object
WS2812 controller class.
Definition FastLED.h:218
#define EVERY_N_MILLISECONDS(N)
Alias for EVERY_N_MILLIS.
Definition lib8tion.h:1221
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:567
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86
#define FL_WARN(X)
Definition warn.h:18