FastLED 3.9.15
Loading...
Searching...
No Matches
MultiArrays.ino
Go to the documentation of this file.
1// @filter: (memory is large)
2
6
7// MultiArrays - see https://github.com/FastLED/FastLED/wiki/Multiple-Controller-Examples for more info on
8// using multiple controllers. In this example, we're going to set up three NEOPIXEL strips on three
9// different pins, each strip getting its own CRGB array to be played with
10
11/*
12 * SAFE PIN REFERENCE FOR MULTI-ARRAY PROJECTS
13 *
14 * When using multiple LED strips, choose pins carefully to avoid conflicts.
15 * Below are tested safe pins for common boards with sufficient memory:
16 *
17 * ESP32-DevKitC (esp32dev) - Original ESP32 WROOM-32:
18 * Safe pins: 2, 4, 5, 12-19, 21-23, 25-27, 32, 33
19 * Best for LED output: 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27
20 * Avoid: 0 (boot button), 1 (TX), 3 (RX), 6-11 (flash), 34-39 (input only)
21 * Notes: GPIO 2 can cause boot issues if pulled high. Avoid strapping pins (0, 2, 5, 12, 15) if possible.
22 *
23 * ESP32-C3 (esp32-c3-devkitm-1):
24 * Safe pins: 0-10 (most are safe after boot)
25 * Best for LED output: 0, 1, 2, 3, 4, 5, 6, 7, 8, 10
26 * Avoid: 9 (boot strapping), 18, 19 (USB if using native USB)
27 * Notes: Fewer pins than ESP32, but most are GPIO capable. Pin 9 is strapping pin (keep low during boot).
28 *
29 * ESP32-S3 (esp32-s3-devkitc-1):
30 * Safe pins: 1-18, 21, 38-48 (many options available)
31 * Best for LED output: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 21, 38, 39, 40, 41, 42
32 * Avoid: 0 (boot button), 19, 20 (USB JTAG by default), 26-32 (flash/PSRAM on some modules), 43, 44 (TX/RX)
33 * Notes: Very flexible GPIO. Avoid 19/20 for USB-JTAG. Pin 1 is safe (avoids GPIO19 USB conflict).
34 *
35 * ESP32-C6:
36 * Safe pins: 0-7, 15-23 (after boot)
37 * Best for LED output: 0, 1, 2, 3, 4, 5, 6, 7, 15, 16, 17, 18, 19, 20, 21, 22, 23
38 * Avoid: 8, 9 (strapping pins), 12, 13 (USB if using native USB)
39 * Notes: Similar to C3 but with more pins. Most GPIO are multi-function capable.
40 *
41 * ESP32-P4 (if using esp32p4-devkit):
42 * Safe pins: Varies by specific module - refer to your dev board documentation
43 * Notes: Industrial ESP32 variant. Check your specific module's datasheet for GPIO capabilities.
44 *
45 * RP2040 (Raspberry Pi Pico):
46 * Safe pins: GP0-GP22, GP26-GP28 (most GPIO pins)
47 * Best for LED output: GP2-GP22 (any of these work well)
48 * Avoid: GP23-GP25 (used for internal functions on Pico)
49 * Notes: Very flexible - nearly all GPIO can be used. GP25 is the onboard LED on Pico.
50 * No special strapping requirements. Consider leaving GP0/GP1 free for UART debugging.
51 *
52 * Teensy 4.0:
53 * Safe pins: 0-23, 24-27 (some constraints), 28-33
54 * Best for LED output: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
55 * Avoid: Pin 13 (onboard LED - can use but may blink), 0 (RX), consider avoiding for debugging
56 * Notes: All digital pins are 3.3V. Very fast GPIO. Most pins work great for LEDs.
57 *
58 * Teensy 4.1:
59 * Safe pins: 0-41, 54-57 (extensive GPIO)
60 * Best for LED output: 1-12, 14-27, 28-39 (many options)
61 * Avoid: Pin 13 (onboard LED), 0 (RX) if using Serial, 40-41 (I2C if using Wire)
62 * Notes: Similar to 4.0 but with many more pins. Excellent for large multi-strip projects.
63 *
64 * Teensy 3.6:
65 * Safe pins: 0-39, 54-57 (many GPIO available)
66 * Best for LED output: 2-12, 14-23, 24-33
67 * Avoid: Pin 13 (onboard LED), 0 (RX), 1 (TX) if using Serial
68 * Notes: 3.3V GPIO. Good memory for multi-strip projects. Predecessor to Teensy 4.x.
69 *
70 * General Recommendations:
71 * - Always test your specific board configuration before deploying
72 * - Start with 2-3 strips to verify pin assignments work correctly
73 * - Check for pin conflicts with other peripherals (SPI, I2C, UART)
74 * - Consider power requirements separately from data pin selection
75 * - For production, avoid pins needed for programming/debugging (TX, RX, USB pins)
76 * - When in doubt, refer to your board's pinout diagram
77 * - Use level shifters if mixing 3.3V boards with 5V LED strips (recommended for reliability)
78 *
79 * NOTE: This example uses platform-specific pin definitions to automatically
80 * select safe pins for your board. Finding truly "universal" safe pins across
81 * all platforms is challenging due to different architectures, boot requirements,
82 * and hardware constraints (strapping pins, flash interfaces, USB, etc.).
83 * The platform detection below handles these differences automatically.
84 * If you need different pins, simply define PIN_RED, PIN_GREEN, and PIN_BLUE
85 * before the platform detection code.
86 */
87
88#include <FastLED.h>
89
90#define NUM_LEDS_PER_STRIP 60
94
95// Platform-specific safe pin definitions
96// These pins are chosen to avoid strapping pins, flash pins, USB pins, etc.
97#if defined(ESP32)
98 // ESP32 variants - use universally safe pins that work across most ESP32 modules
99 #if defined(CONFIG_IDF_TARGET_ESP32C3)
100 // ESP32-C3: Avoid pin 9 (strapping), use safe GPIO
101 #define PIN_RED 2
102 #define PIN_GREEN 3
103 #define PIN_BLUE 4
104 #elif defined(CONFIG_IDF_TARGET_ESP32S3)
105 // ESP32-S3: Use safe pins that avoid USB-JTAG (19, 20) and flash/PSRAM (26-32)
106 #define PIN_RED 1
107 #define PIN_GREEN 2
108 #define PIN_BLUE 3
109 #elif defined(CONFIG_IDF_TARGET_ESP32C6)
110 // ESP32-C6: Avoid strapping pins 8, 9 and USB pins 12, 13
111 #define PIN_RED 2
112 #define PIN_GREEN 3
113 #define PIN_BLUE 4
114 #elif defined(CONFIG_IDF_TARGET_ESP32C5)
115 // ESP32-C5: Avoid strapping pins 2, 7, 25, 27, 28, USB pins 13, 14, and flash pins 16-22
116 #define PIN_RED 3
117 #define PIN_GREEN 4
118 #define PIN_BLUE 5
119 #elif defined(CONFIG_IDF_TARGET_ESP32H2)
120 // ESP32-H2: Avoid flash pins 15-21, strapping pins 2, 3, 8, 9, 25, USB-Serial-JTAG 26, 27
121 #define PIN_RED 0
122 #define PIN_GREEN 1
123 #define PIN_BLUE 4
124 #elif defined(CONFIG_IDF_TARGET_ESP32C2)
125 // ESP32-C2: Only GPIO 0-20 available. Avoid flash pins 11-17, strapping pins 8, 9
126 #define PIN_RED 0
127 #define PIN_GREEN 1
128 #define PIN_BLUE 2
129 #else
130 // ESP32 classic (WROOM-32, WROVER, etc): Avoid strapping and flash pins
131 #define PIN_RED 13
132 #define PIN_GREEN 14
133 #define PIN_BLUE 15
134 #endif
135#elif defined(ARDUINO_ARCH_RP2040)
136 // RP2040 (Raspberry Pi Pico): Most GPIO are safe, using mid-range pins
137 #define PIN_RED 10
138 #define PIN_GREEN 11
139 #define PIN_BLUE 12
140#elif defined(__IMXRT1062__)
141 // Teensy 4.0/4.1: Most pins are safe, using common GPIO
142 #define PIN_RED 2
143 #define PIN_GREEN 3
144 #define PIN_BLUE 4
145#elif defined(__MK66FX1M0__) || defined(__MK64FX512__)
146 // Teensy 3.6: Safe pins away from Serial
147 #define PIN_RED 2
148 #define PIN_GREEN 3
149 #define PIN_BLUE 4
150#else
151 // Universal fallback for other platforms (AVR, etc.)
152 // These are common digital pins on most Arduino boards
153 #define PIN_RED 6
154 #define PIN_GREEN 7
155 #define PIN_BLUE 8
156#endif
157
158// For mirroring strips, all the "special" stuff happens just in setup. We
159// just addLeds multiple times, once for each strip
160void setup() {
161 // tell FastLED there's 60 NEOPIXEL leds on pin PIN_RED
162 FastLED.addLeds<NEOPIXEL, PIN_RED>(redLeds, NUM_LEDS_PER_STRIP);
163
164 // tell FastLED there's 60 NEOPIXEL leds on pin PIN_GREEN
165 FastLED.addLeds<NEOPIXEL, PIN_GREEN>(greenLeds, NUM_LEDS_PER_STRIP);
166
167 // tell FastLED there's 60 NEOPIXEL leds on pin PIN_BLUE
168 FastLED.addLeds<NEOPIXEL, PIN_BLUE>(blueLeds, NUM_LEDS_PER_STRIP);
169
170}
171
172void loop() {
173 for(int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
174 // set our current dot to red, green, and blue
175 redLeds[i] = CRGB::Red;
177 blueLeds[i] = CRGB::Blue;
178 FastLED.show();
179 // clear our current dot before we move on
180 redLeds[i] = CRGB::Black;
183 delay(100);
184 }
185
186 for(int i = NUM_LEDS_PER_STRIP-1; i >= 0; i--) {
187 // set our current dot to red, green, and blue
188 redLeds[i] = CRGB::Red;
190 blueLeds[i] = CRGB::Blue;
191 FastLED.show();
192 // clear our current dot before we move on
193 redLeds[i] = CRGB::Black;
196 delay(100);
197 }
198}
void setup()
void loop()
#define NUM_LEDS_PER_STRIP
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
CRGB blueLeds[NUM_LEDS_PER_STRIP]
#define PIN_GREEN
CRGB greenLeds[NUM_LEDS_PER_STRIP]
#define PIN_BLUE
CRGB redLeds[NUM_LEDS_PER_STRIP]
#define PIN_RED
fl::CRGB CRGB
Definition crgb.h:25
@ Green
<div style='background:#008000;width:4em;height:4em;'></div>
Definition crgb.h:558
@ Red
<div style='background:#FF0000;width:4em;height:4em;'></div>
Definition crgb.h:622
@ Blue
<div style='background:#0000FF;width:4em;height:4em;'></div>
Definition crgb.h:512
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:510