FastLED 3.9.15
Loading...
Searching...
No Matches
Esp32S3I2SDemo.ino
Go to the documentation of this file.
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? (the pins can be defined arbitrarily,Tested on esp32s3, esp32duino version 3.2.0)
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
107
108fl::InternalI2SDriver *driver = nullptr;
110
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.
116 );
119 );
122 );
125 );
128 );
131 );
134 );
137 );
140 );
143 );
146 );
149 );
152 );
155 );
158 );
161 );
162 FastLED.setBrightness(32);
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) {
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() {
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}
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
#define NUM_LEDS
Definition Apa102.ino:6
#define EXAMPLE_PIN_NUM_DATA2
#define EXAMPLE_PIN_NUM_DATA11
#define EXAMPLE_PIN_NUM_DATA8
#define NUM_LEDS_PER_STRIP
#define EXAMPLE_PIN_NUM_DATA6
#define EXAMPLE_PIN_NUM_DATA0
#define EXAMPLE_PIN_NUM_DATA12
void setup()
#define EXAMPLE_PIN_NUM_DATA15
void fill_rainbow(CRGB *all_leds)
#define EXAMPLE_PIN_NUM_DATA4
#define EXAMPLE_PIN_NUM_DATA9
#define EXAMPLE_PIN_NUM_DATA5
fl::InternalI2SDriver * driver
void setup_i2s_using_fastled_api()
const bool gUseFastLEDApi
#define EXAMPLE_PIN_NUM_DATA7
#define NUMSTRIPS
#define EXAMPLE_PIN_NUM_DATA13
#define EXAMPLE_PIN_NUM_DATA10
#define EXAMPLE_PIN_NUM_DATA1
#define EXAMPLE_PIN_NUM_DATA14
int PINS[]
#define EXAMPLE_PIN_NUM_DATA3
void loop()
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:58
central include file for FastLED, defines the CFastLED class/object
#define FASTLED_ASSERT(x, MSG)
Definition assert.h:9
WS2812 controller class.
Definition FastLED.h:193
@ GRB
Green, Red, Blue (0102)
Definition eorder.h:17
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