FastLED 3.9.12
Loading...
Searching...
No Matches
Esp32S3I2SDemo.ino
1
2
32// PLATFORMIO BUILD FLAGS:
33// Define your platformio.ini like so:
34//
35// [env:esp32s3]
36// platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.04/platform-espressif32.zip
37// framework = arduino
38// board = seeed_xiao_esp32s3
39// build_flags =
40// ${env:generic-esp.build_flags}
41// -DBOARD_HAS_PSRAM
42// -mfix-esp32-psram-cache-issue
43// -mfix-esp32-psram-cache-strategy=memw
44// board_build.partitions = huge_app.csv
45//
46// Then in your setup function you are going to want to call psramInit();
47//
48// Want to get a contributor badge for FastLED? This driver has only been lightly tested.
49// There are certain open questions:
50// - Can the pins order for the strips be changed?
51// - Are there some combination of pins that can be ommitted?
52// - What other caveats are there?
53//
54// If you know the answer to these questions then please submit a PR to the FastLED repo and
55// we will update the information for the community.
56
57#include <esp_psram.h>
58
59#define FASTLED_USES_ESP32S3_I2S
60
61#include "FastLED.h"
62#include "fl/assert.h"
63
64
65#define NUMSTRIPS 16
66#define NUM_LEDS_PER_STRIP 256
67#define NUM_LEDS (NUM_LEDS_PER_STRIP * NUMSTRIPS)
68
69#define EXAMPLE_PIN_NUM_DATA0 19 // B0
70#define EXAMPLE_PIN_NUM_DATA1 45 // B1
71#define EXAMPLE_PIN_NUM_DATA2 21 // B2
72#define EXAMPLE_PIN_NUM_DATA3 6 // B3
73#define EXAMPLE_PIN_NUM_DATA4 7 // B4
74#define EXAMPLE_PIN_NUM_DATA5 8 // G0
75#define EXAMPLE_PIN_NUM_DATA6 9 // G1
76#define EXAMPLE_PIN_NUM_DATA7 10 // G2
77#define EXAMPLE_PIN_NUM_DATA8 11 // G3
78#define EXAMPLE_PIN_NUM_DATA9 12 // G4
79#define EXAMPLE_PIN_NUM_DATA10 13 // G5
80#define EXAMPLE_PIN_NUM_DATA11 14 // R0
81#define EXAMPLE_PIN_NUM_DATA12 15 // R1
82#define EXAMPLE_PIN_NUM_DATA13 16 // R2
83#define EXAMPLE_PIN_NUM_DATA14 17 // R3
84#define EXAMPLE_PIN_NUM_DATA15 18 // R4
85
86
87const bool gUseFastLEDApi = true; // Set this to false to use the raw driver.
88
89int PINS[] = {
90 EXAMPLE_PIN_NUM_DATA0,
91 EXAMPLE_PIN_NUM_DATA1,
92 EXAMPLE_PIN_NUM_DATA2,
93 EXAMPLE_PIN_NUM_DATA3,
94 EXAMPLE_PIN_NUM_DATA4,
95 EXAMPLE_PIN_NUM_DATA5,
96 EXAMPLE_PIN_NUM_DATA6,
97 EXAMPLE_PIN_NUM_DATA7,
98 EXAMPLE_PIN_NUM_DATA8,
99 EXAMPLE_PIN_NUM_DATA9,
100 EXAMPLE_PIN_NUM_DATA10,
101 EXAMPLE_PIN_NUM_DATA11,
102 EXAMPLE_PIN_NUM_DATA12,
103 EXAMPLE_PIN_NUM_DATA13,
104 EXAMPLE_PIN_NUM_DATA14,
105 EXAMPLE_PIN_NUM_DATA15
106};
107
108fl::InternalI2SDriver *driver = nullptr;
109CRGB leds[NUM_LEDS];
110
111void setup_i2s_using_fastled_api() {
112 // Note, in this case we are using contingious memory for the leds. But this is not required.
113 // Each strip can be a different size and the FastLED api will upscale the smaller strips to the largest strip.
114 FastLED.addLeds<WS2812, EXAMPLE_PIN_NUM_DATA0, GRB>(
115 leds + (0 * NUM_LEDS_PER_STRIP), NUM_LEDS_PER_STRIP
116 );
117 FastLED.addLeds<WS2812, EXAMPLE_PIN_NUM_DATA1, GRB>(
118 leds + (1 * NUM_LEDS_PER_STRIP), NUM_LEDS_PER_STRIP
119 );
120 FastLED.addLeds<WS2812, EXAMPLE_PIN_NUM_DATA2, GRB>(
121 leds + (2 * NUM_LEDS_PER_STRIP), NUM_LEDS_PER_STRIP
122 );
123 FastLED.addLeds<WS2812, EXAMPLE_PIN_NUM_DATA3, GRB>(
124 leds + (3 * NUM_LEDS_PER_STRIP), NUM_LEDS_PER_STRIP
125 );
126 FastLED.addLeds<WS2812, EXAMPLE_PIN_NUM_DATA4, GRB>(
127 leds + (4 * NUM_LEDS_PER_STRIP), NUM_LEDS_PER_STRIP
128 );
129 FastLED.addLeds<WS2812, EXAMPLE_PIN_NUM_DATA5, GRB>(
130 leds + (5 * NUM_LEDS_PER_STRIP), NUM_LEDS_PER_STRIP
131 );
132 FastLED.addLeds<WS2812, EXAMPLE_PIN_NUM_DATA6, GRB>(
133 leds + (6 * NUM_LEDS_PER_STRIP), NUM_LEDS_PER_STRIP
134 );
135 FastLED.addLeds<WS2812, EXAMPLE_PIN_NUM_DATA7, GRB>(
136 leds + (7 * NUM_LEDS_PER_STRIP), NUM_LEDS_PER_STRIP
137 );
138 FastLED.addLeds<WS2812, EXAMPLE_PIN_NUM_DATA8, GRB>(
139 leds + (8 * NUM_LEDS_PER_STRIP), NUM_LEDS_PER_STRIP
140 );
141 FastLED.addLeds<WS2812, EXAMPLE_PIN_NUM_DATA9, GRB>(
142 leds + (9 * NUM_LEDS_PER_STRIP), NUM_LEDS_PER_STRIP
143 );
144 FastLED.addLeds<WS2812, EXAMPLE_PIN_NUM_DATA10, GRB>(
145 leds + (10 * NUM_LEDS_PER_STRIP), NUM_LEDS_PER_STRIP
146 );
147 FastLED.addLeds<WS2812, EXAMPLE_PIN_NUM_DATA11, GRB>(
148 leds + (11 * NUM_LEDS_PER_STRIP), NUM_LEDS_PER_STRIP
149 );
150 FastLED.addLeds<WS2812, EXAMPLE_PIN_NUM_DATA12, GRB>(
151 leds + (12 * NUM_LEDS_PER_STRIP), NUM_LEDS_PER_STRIP
152 );
153 FastLED.addLeds<WS2812, EXAMPLE_PIN_NUM_DATA13, GRB>(
154 leds + (13 * NUM_LEDS_PER_STRIP), NUM_LEDS_PER_STRIP
155 );
156 FastLED.addLeds<WS2812, EXAMPLE_PIN_NUM_DATA14, GRB>(
157 leds + (14 * NUM_LEDS_PER_STRIP), NUM_LEDS_PER_STRIP
158 );
159 FastLED.addLeds<WS2812, EXAMPLE_PIN_NUM_DATA15, GRB>(
160 leds + (15 * NUM_LEDS_PER_STRIP), NUM_LEDS_PER_STRIP
161 );
163}
164
165
166
167void setup() {
168 psramInit(); // IMPORTANT: This is required to enable PSRAM. If you don't do this, the driver will not work.
169 // put your setup code here, to run once:
170 Serial.begin(115200);
171
172 // This is used so that you can see if PSRAM is enabled. If not, we will crash in setup() or in loop().
173 log_d("Total heap: %d", ESP.getHeapSize());
174 log_d("Free heap: %d", ESP.getFreeHeap());
175 log_d("Total PSRAM: %d", ESP.getPsramSize()); // If this prints out 0, then PSRAM is not enabled.
176 log_d("Free PSRAM: %d", ESP.getFreePsram());
177
178 log_d("waiting 6 second before startup");
179 delay(6000); // The long reset time here is to make it easier to flash the device during the development process.
180 if (gUseFastLEDApi) {
181 setup_i2s_using_fastled_api();
182 } else {
183 driver = fl::InternalI2SDriver::create();
184 driver->initled((uint8_t *)leds, PINS, NUMSTRIPS, NUM_LEDS_PER_STRIP); // Skips extra frame buffer copy.
185 driver->setBrightness(32);
186 }
187}
188
189void fill_rainbow(CRGB* all_leds) {
190 static int s_offset = 0;
191 for (int j = 0; j < NUMSTRIPS; j++) {
192 for (int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
193 int idx = (i + s_offset) % NUM_LEDS_PER_STRIP + NUM_LEDS_PER_STRIP * j;
194 all_leds[idx] = CHSV(i, 255, 255);
195 }
196 }
197 s_offset++;
198}
199
200void loop() {
201 fill_rainbow(leds);
202 if (gUseFastLEDApi) {
203 FastLED.show();
204 } else {
205 FASTLED_ASSERT(driver != nullptr, "Did not expect driver to be null");
206 driver->show();
207 }
208}
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:45
central include file for FastLED, defines the CFastLED class/object
void setBrightness(uint8_t scale)
Set the global brightness scaling.
Definition FastLED.h:719
void show(uint8_t scale)
Update all our controllers with the current led colors, using the passed in brightness.
Definition FastLED.cpp:94
static CLEDController & addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a CLEDController instance to the world.
Definition FastLED.cpp:79
WS2812 controller class.
Definition FastLED.h:190
@ GRB
Green, Red, Blue (0102)
Definition eorder.h:17
void fill_rainbow(struct CRGB *targetArray, int numToFill, uint8_t initialhue, uint8_t deltahue)
Fill a range of LEDs with a rainbow of colors.
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Definition chsv.h:16
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54