FastLED 3.9.15
Loading...
Searching...
No Matches
MirroringSample.ino
Go to the documentation of this file.
1// @filter: (memory is large)
2
6
7// MirroringSample - 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 four NEOPIXEL strips on four
9// different pins, and show the same thing on all four of them, a simple bouncing dot/cyclon type pattern
10//
11// NOTE: This example uses platform-specific pin definitions to automatically select safe pins
12// for your board. Finding truly "universal" safe pins across all platforms is challenging due
13// to different architectures, boot requirements, and hardware constraints (strapping pins,
14// flash interfaces, USB, etc.). The platform detection below handles these differences automatically.
15
16// FastLED.h must be included first to trigger precompiled headers for FastLED's build system
17#include "FastLED.h"
18
19#include <FastLED.h>
20
21#define NUM_LEDS_PER_STRIP 60
23
24// Platform-specific safe pin definitions
25// These pins are chosen to avoid strapping pins, flash pins, USB pins, etc.
26#if defined(ESP32)
27 // ESP32 variants - use universally safe pins that work across most ESP32 modules
28 #if defined(CONFIG_IDF_TARGET_ESP32C3)
29 // ESP32-C3: Avoid pin 9 (strapping), use safe GPIO
30 #define PIN_1 2
31 #define PIN_2 3
32 #define PIN_3 4
33 #define PIN_4 5
34 #elif defined(CONFIG_IDF_TARGET_ESP32S3)
35 // ESP32-S3: Use safe pins that avoid USB-JTAG (19, 20) and flash/PSRAM (26-32)
36 #define PIN_1 1
37 #define PIN_2 2
38 #define PIN_3 3
39 #define PIN_4 4
40 #elif defined(CONFIG_IDF_TARGET_ESP32C6)
41 // ESP32-C6: Avoid strapping pins 8, 9 and USB pins 12, 13
42 #define PIN_1 2
43 #define PIN_2 3
44 #define PIN_3 4
45 #define PIN_4 5
46 #elif defined(CONFIG_IDF_TARGET_ESP32C5)
47 // ESP32-C5: Avoid strapping pins 2, 7, 25, 27, 28, USB pins 13, 14, and flash pins 16-22
48 #define PIN_1 3
49 #define PIN_2 4
50 #define PIN_3 5
51 #define PIN_4 8
52 #elif defined(CONFIG_IDF_TARGET_ESP32H2)
53 // ESP32-H2: Avoid flash pins 15-21, strapping pins 2, 3, 8, 9, 25, USB-Serial-JTAG 26, 27
54 #define PIN_1 0
55 #define PIN_2 1
56 #define PIN_3 4
57 #define PIN_4 5
58 #elif defined(CONFIG_IDF_TARGET_ESP32C2)
59 // ESP32-C2: Only GPIO 0-20 available. Avoid flash pins 11-17, strapping pins 8, 9
60 #define PIN_1 0
61 #define PIN_2 1
62 #define PIN_3 2
63 #define PIN_4 3
64 #else
65 // ESP32 classic (WROOM-32, WROVER, etc): Avoid strapping and flash pins
66 #define PIN_1 13
67 #define PIN_2 14
68 #define PIN_3 15
69 #define PIN_4 16
70 #endif
71#elif defined(ARDUINO_ARCH_RP2040)
72 // RP2040 (Raspberry Pi Pico): Most GPIO are safe, using mid-range pins
73 #define PIN_1 10
74 #define PIN_2 11
75 #define PIN_3 12
76 #define PIN_4 13
77#elif defined(__IMXRT1062__)
78 // Teensy 4.0/4.1: Most pins are safe, using common GPIO
79 #define PIN_1 2
80 #define PIN_2 3
81 #define PIN_3 4
82 #define PIN_4 5
83#elif defined(__MK66FX1M0__) || defined(__MK64FX512__)
84 // Teensy 3.6: Safe pins away from Serial
85 #define PIN_1 2
86 #define PIN_2 3
87 #define PIN_3 4
88 #define PIN_4 5
89#else
90 // Universal fallback for other platforms (AVR, etc.)
91 // These are common digital pins on most Arduino boards
92 #define PIN_1 4
93 #define PIN_2 5
94 #define PIN_3 6
95 #define PIN_4 7
96#endif
97
98// For mirroring strips, all the "special" stuff happens just in setup. We
99// just addLeds multiple times, once for each strip
100void setup() {
101 // tell FastLED there's 60 NEOPIXEL leds on pin PIN_1
102 FastLED.addLeds<NEOPIXEL, PIN_1>(leds, NUM_LEDS_PER_STRIP);
103
104 // tell FastLED there's 60 NEOPIXEL leds on pin PIN_2
105 FastLED.addLeds<NEOPIXEL, PIN_2>(leds, NUM_LEDS_PER_STRIP);
106
107 // tell FastLED there's 60 NEOPIXEL leds on pin PIN_3
108 FastLED.addLeds<NEOPIXEL, PIN_3>(leds, NUM_LEDS_PER_STRIP);
109
110 // tell FastLED there's 60 NEOPIXEL leds on pin PIN_4
111 FastLED.addLeds<NEOPIXEL, PIN_4>(leds, NUM_LEDS_PER_STRIP);
112}
113
114void loop() {
115 for(int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
116 // set our current dot to red
117 leds[i] = CRGB::Red;
118 FastLED.show();
119 // clear our current dot before we move on
120 leds[i] = CRGB::Black;
121 delay(100);
122 }
123
124 for(int i = NUM_LEDS_PER_STRIP-1; i >= 0; i--) {
125 // set our current dot to red
126 leds[i] = CRGB::Red;
127 FastLED.show();
128 // clear our current dot before we move on
129 leds[i] = CRGB::Black;
130 delay(100);
131 }
132}
void setup()
void loop()
fl::CRGB leds[NUM_LEDS]
#define NUM_LEDS_PER_STRIP
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
#define PIN_1
#define PIN_2
#define PIN_4
#define PIN_3
fl::CRGB CRGB
Definition crgb.h:25
@ Red
<div style='background:#FF0000;width:4em;height:4em;'></div>
Definition crgb.h:622
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:510