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