FastLED
3.9.15
Loading...
Searching...
No Matches
ParallelOutputDemo.h
Go to the documentation of this file.
1
2
7
8
#include <FastLED.h>
9
10
#define NUM_LEDS_PER_STRIP 16
11
// Note: this can be 12 if you're using a teensy 3 and don't mind soldering the pads on the back
12
#define NUM_STRIPS 16
13
14
CRGB
leds
[
NUM_STRIPS
*
NUM_LEDS_PER_STRIP
];
15
16
// ============================================================================
17
// PORT CONTROLLER BACKEND - Compile-time Template Specialization
18
// ============================================================================
19
//
20
// IMPORTANT CONCEPT: WS2811_PORTDC, WS2811_PORTA, etc. are NOT runtime port
21
// variables. They are compile-time template aliases that select specialized
22
// FastLED controller classes for parallel pin output.
23
//
24
// How it works:
25
// 1. WS2811_PORTDC is a type alias expanding to a controller class template
26
// 2. This class is specialized to know the exact pin layout for PORTD+C pins
27
// 3. The pins are baked in as FastPin<2,14,7,8,6,20,21,5,15,22,23,9,10,13,11,12>
28
// 4. At compile time, FastLED generates optimized assembly with direct
29
// hardware register writes (GPIOA_PDOR, etc.) with precise timing
30
// 5. This achieves parallel LED output with minimal overhead
31
//
32
// The "port" is a symbolic handle that tells the compiler:
33
// "Use the CWS2811Controller implementation optimized for THIS specific
34
// group of pins on THIS hardware port"
35
//
36
// This is why it compiles as template<typename CHIPSET, int NUM_LANES>
37
// — all specialization happens at compile-time, not runtime.
38
//
39
// ============================================================================
40
// PIN LAYOUTS
41
// ============================================================================
42
//
43
// Teensy 3/3.1 (16-way parallel):
44
// WS2811_PORTD: 2,14,7,8,6,20,21,5
45
// WS2811_PORTC: 15,22,23,9,10,13,11,12,28,27,29,30
46
// (last 4 are pads on bottom of Teensy)
47
// WS2811_PORTDC: 2,14,7,8,6,20,21,5,15,22,23,9,10,13,11,12
48
// (combined D+C for 16-way parallel output)
49
//
50
// Arduino Due (port variants):
51
// WS2811_PORTA: 69,68,61,60,59,100,58,31
52
// (pin 100 only available on the digix)
53
// WS2811_PORTB: 90,91,92,93,94,95,96,97
54
// (only available on the digix)
55
// WS2811_PORTD: 25,26,27,28,14,15,29,11
56
//
57
58
59
// IBCC<WS2811, 1, 16> outputs;
60
61
void
setup
() {
62
delay(5000);
63
Serial
.begin(57600);
64
Serial
.println(
"Starting..."
);
65
#if defined(HAS_PORTDC)
66
// Teensy 3 parallel output example using port controller backend.
67
//
68
// fastLED.addLeds<WS2811_PORTDC, NUM_STRIPS>(...) invokes the compiler
69
// to select and specialize the CWS2811Controller<> template for the
70
// PORTDC pin configuration. The template is instantiated with knowledge
71
// of which pins belong to which ports, enabling direct hardware register
72
// access with precise timing for all 16 parallel LED outputs.
73
//
74
// Alternative port controller options (commented out):
75
// FastLED.addLeds<WS2811_PORTA,NUM_STRIPS>(leds, NUM_LEDS_PER_STRIP);
76
// FastLED.addLeds<WS2811_PORTB,NUM_STRIPS>(leds, NUM_LEDS_PER_STRIP);
77
// FastLED.addLeds<WS2811_PORTD,NUM_STRIPS>(leds, NUM_LEDS_PER_STRIP).setCorrection(TypicalLEDStrip);
78
//
79
// Using PORTDC for 16-way parallel output (combined ports D and C):
80
FastLED
.addLeds<WS2811_PORTDC,
NUM_STRIPS
>(
leds
,
NUM_LEDS_PER_STRIP
);
81
#else
82
// NOTE: Parallel port output requires HAS_PORTDC support (Teensy 3.x only).
83
// Teensy 4.x does NOT support the WS2811_PORTDC style parallel output.
84
// For Teensy 4.x, use single-lane output on GPIO pins or consider
85
// alternative approaches for parallel LED control.
86
Serial
.println(
"Parallel port output not supported on this platform"
);
87
#endif
88
}
89
90
void
loop
() {
91
Serial
.println(
"Loop...."
);
92
static
uint8_t
hue
= 0;
// okay static in header
93
for
(
int
i = 0; i <
NUM_STRIPS
; i++) {
94
for
(
int
j = 0; j <
NUM_LEDS_PER_STRIP
; j++) {
95
leds
[(i*
NUM_LEDS_PER_STRIP
) + j] =
CHSV
((32*i) +
hue
+j,192,255);
96
}
97
}
98
99
// Set the first n leds on each strip to show which strip it is
100
for
(
int
i = 0; i <
NUM_STRIPS
; i++) {
101
for
(
int
j = 0; j <= i; j++) {
102
leds
[(i*
NUM_LEDS_PER_STRIP
) + j] =
CRGB::Red
;
103
}
104
}
105
106
hue
++;
107
108
FastLED
.show();
109
// FastLED.delay(100);
110
}
leds
fl::CRGB leds[NUM_LEDS]
Definition
Animartrix.ino:93
NUM_LEDS_PER_STRIP
#define NUM_LEDS_PER_STRIP
Definition
ArrayOfLedArrays.ino:15
NUM_STRIPS
#define NUM_STRIPS
Definition
ArrayOfLedArrays.ino:14
FastLED
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
Definition
FastLED.cpp.hpp:75
setup
void setup()
Definition
ParallelOutputDemo.h:61
loop
void loop()
Definition
ParallelOutputDemo.h:90
hue
uint8_t hue
Definition
advanced.h:94
CHSV
fl::hsv8 CHSV
Definition
chsv.h:11
CRGB
fl::CRGB CRGB
Definition
crgb.h:25
fl::CRGB::Red
@ Red
<div style='background:#FF0000;width:4em;height:4em;'></div>
Definition
crgb.h:622
Serial
#define Serial
Definition
serial.h:304
examples
Multiple
ParallelOutputDemo
ParallelOutputDemo.h
Generated on Tue Jun 16 2026 00:06:58 for FastLED by
1.13.2