FastLED 3.9.15
Loading...
Searching...
No Matches
ParallelSPI.ino
Go to the documentation of this file.
1
48
49// ============================================================================
50// CONFIGURATION - Edit these to match your hardware
51// ============================================================================
52
53// Number of parallel LED strips (must be 2, 4, or 8)
54#define NUM_STRIPS 2
55
56// Number of LEDs per strip (all strips should have the same length)
57#define NUM_LEDS 30
58
59// Shared clock pin for ALL strips - this is critical for parallel mode!
60// Recommendation for ESP32: Use GPIO 18, 19, or 23 (standard SPI clock pins)
61#define LED_CLOCK_PIN 18
62
63// Data pin assignments (edit if needed for your board)
64// Recommendation for ESP32: Avoid strapping pins 0, 2, 15
65#define LED_DATA_PIN_0 4 // Strip 0 data pin
66#define LED_DATA_PIN_1 5 // Strip 1 data pin
67#define LED_DATA_PIN_2 12 // Strip 2 data pin (only used if NUM_STRIPS >= 4)
68#define LED_DATA_PIN_3 13 // Strip 3 data pin (only used if NUM_STRIPS >= 4)
69#define LED_DATA_PIN_4 16 // Strip 4 data pin (only used if NUM_STRIPS >= 8)
70#define LED_DATA_PIN_5 17 // Strip 5 data pin (only used if NUM_STRIPS >= 8)
71#define LED_DATA_PIN_6 21 // Strip 6 data pin (only used if NUM_STRIPS >= 8)
72#define LED_DATA_PIN_7 22 // Strip 7 data pin (only used if NUM_STRIPS >= 8)
73
74#include <FastLED.h>
75
76// This example is only compiled for stub platform or ESP32
77#if defined(FASTLED_STUB_PLATFORM)
78
79// Validate configuration
80#if NUM_STRIPS != 2 && NUM_STRIPS != 4 && NUM_STRIPS != 8
81 #error "NUM_STRIPS must be 2, 4, or 8"
82#endif
83
84// Check platform support
85#if !defined(FASTLED_SPI_HOST_SIMULATION) && !defined(ESP32)
86 #error "This example requires ESP32 or host simulation platform"
87#endif
88
89// Define LED arrays - one per strip
91
92// Animation state
93uint8_t hue = 0;
94
95void setup() {
96 Serial.begin(115200);
97 delay(2000);
98
99 Serial.println("FastLED Parallel Output Example");
100 Serial.println("================================");
101 Serial.print("Number of strips: ");
102 Serial.println(NUM_STRIPS);
103 Serial.print("LEDs per strip: ");
104 Serial.println(NUM_LEDS);
105 Serial.print("Clock pin: GPIO");
106 Serial.println(LED_CLOCK_PIN);
107
108 // ========================================================================
109 // Register LED strips with FastLED
110 // ========================================================================
111 // CRITICAL: All strips use the SAME clock pin (CLOCK_PIN)
112 // This shared clock pin is what triggers FastLED's parallel SPI mode!
113 // The hardware will automatically send data to all strips simultaneously.
114
115 #if NUM_STRIPS >= 2
118 Serial.println("Strip 0: Data=GPIO" + String(LED_DATA_PIN_0) + ", Clock=GPIO" + String(LED_CLOCK_PIN));
119 Serial.println("Strip 1: Data=GPIO" + String(LED_DATA_PIN_1) + ", Clock=GPIO" + String(LED_CLOCK_PIN));
120 #endif
121
122 #if NUM_STRIPS >= 4
125 Serial.println("Strip 2: Data=GPIO" + String(LED_DATA_PIN_2) + ", Clock=GPIO" + String(LED_CLOCK_PIN));
126 Serial.println("Strip 3: Data=GPIO" + String(LED_DATA_PIN_3) + ", Clock=GPIO" + String(LED_CLOCK_PIN));
127 #endif
128
129 #if NUM_STRIPS >= 8
134 Serial.println("Strip 4: Data=GPIO" + String(LED_DATA_PIN_4) + ", Clock=GPIO" + String(LED_CLOCK_PIN));
135 Serial.println("Strip 5: Data=GPIO" + String(LED_DATA_PIN_5) + ", Clock=GPIO" + String(LED_CLOCK_PIN));
136 Serial.println("Strip 6: Data=GPIO" + String(LED_DATA_PIN_6) + ", Clock=GPIO" + String(LED_CLOCK_PIN));
137 Serial.println("Strip 7: Data=GPIO" + String(LED_DATA_PIN_7) + ", Clock=GPIO" + String(LED_CLOCK_PIN));
138 #endif
139
140 Serial.println("================================");
141 Serial.println("Setup complete!");
142 Serial.println("");
143}
144
145void loop() {
146 // Create a different effect on each strip
147
148 // Strip 0: Rainbow wave
149 for (int i = 0; i < NUM_LEDS; i++) {
150 leds[0][i] = CHSV(hue + (i * 256 / NUM_LEDS), 255, 255);
151 }
152
153 #if NUM_STRIPS >= 2
154 // Strip 1: Pulse effect
155 uint8_t brightness = beatsin8(60, 0, 255);
156 fill_solid(leds[1], NUM_LEDS, CHSV(hue + 85, 255, brightness));
157 #endif
158
159 #if NUM_STRIPS >= 4
160 // Strip 2: Moving dot
162 uint8_t pos = beatsin8(30, 0, NUM_LEDS - 1);
163 leds[2][pos] = CHSV(hue + 170, 255, 255);
164
165 // Strip 3: Static color
166 fill_solid(leds[3], NUM_LEDS, CHSV(hue, 255, 255));
167 #endif
168
169 #if NUM_STRIPS >= 8
170 // Strip 4: Rainbow fill
171 fill_rainbow(leds[4], NUM_LEDS, hue, 7);
172
173 // Strip 5: Sine wave brightness
174 for (int i = 0; i < NUM_LEDS; i++) {
175 uint8_t b = sin8(hue + (i * 8));
176 leds[5][i] = CHSV(160, 255, b);
177 }
178
179 // Strip 6: Alternating colors
180 for (int i = 0; i < NUM_LEDS; i++) {
181 leds[6][i] = (i % 2) ? CHSV(hue, 255, 255) : CHSV(hue + 128, 255, 255);
182 }
183
184 // Strip 7: Fire effect simulation
185 for (int i = 0; i < NUM_LEDS; i++) {
186 uint8_t heat = random8(128, 255);
187 leds[7][i] = CHSV(random8(20), 255, heat);
188 }
189 #endif
190
191 // Update all strips simultaneously - this is where parallel output shines!
192 FastLED.show();
193
194 // Advance animation
195 hue++;
196
197 // Print frame rate every 100 frames
199 static uint32_t frameCount = 0;
200 static uint32_t lastTime = millis();
201 uint32_t now = millis();
202 uint32_t elapsed = now - lastTime;
203
204 if (elapsed > 0) {
205 uint32_t fps = (frameCount * 1000) / elapsed;
206 Serial.print("FPS: ");
207 Serial.println(fps);
208
209 frameCount = 0;
210 lastTime = now;
211 }
212 frameCount++;
213 }
214}
215#else
216void setup() {}
217void loop() {}
218
219#endif // defined(FASTLED_STUB_PLATFORM)
void setup()
void loop()
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
#define NUM_STRIPS
uint8_t pos
Definition Blur.ino:11
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
@ APA102
APA102 LED chipset.
Definition FastLED.h:262
uint8_t heat[NUM_LEDS]
Definition Fire2023.h:100
#define LED_DATA_PIN_1
#define LED_DATA_PIN_0
#define LED_DATA_PIN_3
#define LED_DATA_PIN_5
#define LED_DATA_PIN_4
#define LED_CLOCK_PIN
#define LED_DATA_PIN_6
#define LED_DATA_PIN_2
#define LED_DATA_PIN_7
uint8_t hue
Definition advanced.h:94
void fill_rainbow(CRGB *targetArray, int numToFill, fl::u8 initialhue, fl::u8 deltahue=5) FL_NOEXCEPT
Fill a range of LEDs with a rainbow of colors.
Definition fill.cpp.hpp:29
void fill_solid(CRGB *targetArray, int numToFill, const CRGB &color) FL_NOEXCEPT
Fill a range of LEDs with a solid color.
Definition fill.cpp.hpp:9
constexpr EOrder BGR
Definition eorder.h:22
fl::hsv8 CHSV
Definition chsv.h:11
fl::CRGB CRGB
Definition crgb.h:25
LIB8STATIC fl::u8 random8() FL_NOEXCEPT
Generate an 8-bit random number.
Definition random8.h:53
#define EVERY_N_MILLISECONDS(N)
Alias for EVERY_N_MILLIS.
Definition lib8tion.h:1045
LIB8STATIC u8 beatsin8(accum88 beats_per_minute, u8 lowest=0, u8 highest=255, u32 timebase=0, u8 phase_offset=0) FL_NOEXCEPT
Generates an 8-bit sine wave at a given BPM that oscillates within a given range.
Definition beat.h:105
fl::u32 uint32_t
Definition s16x16x4.h:219
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
unsigned char uint8_t
Definition s16x16x4.h:209
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:510
#define Serial
Definition serial.h:304