FastLED 3.9.15
Loading...
Searching...
No Matches
AudioReactive.ino
Go to the documentation of this file.
1// @filter: (mem is large) and ((platform is teensy) or (platform is esp32))
2
3// Audio Reactive LEDs using FastLED.add(Config)
4// Demonstrates the auto-pumped audio pipeline: mic → processor → callbacks → LEDs
5
6#include "FastLED.h"
7
8#if defined(FL_IS_TEENSY)
9// Keep fbuild's library scanner aware of PJRC Audio sources for Teensy.
10#include <Audio.h>
11#endif
12
13#define NUM_LEDS 60
14#define LED_PIN 2
15
16// I2S pins for INMP441 microphone (adjust for your board)
17#define I2S_WS 7
18#define I2S_SD 8
19#define I2S_CLK 4
20
23
24void setup() {
25 Serial.begin(115200);
26 FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
27 FastLED.setBrightness(128);
28
30 audio = FastLED.add(config);
31 audio->setGain(2.0f); // Boost input by 2x
32
33 // Flash white on every beat
34 audio->onBeat([] {
36 });
37
38 // Map bass level to hue
39 audio->onBass([](float level) {
40 uint8_t hue = static_cast<uint8_t>(level * 160);
41 fill_solid(leds, NUM_LEDS, CHSV(hue, 255, 255));
42 });
43
44 // Dim to black on silence
45 audio->onSilenceStart([] {
47 });
48}
49
50void loop() {
52 FastLED.show();
53}
fl::UIAudio audio("Audio Input")
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
#define LED_PIN
#define I2S_CLK
#define I2S_SD
void setup()
#define I2S_WS
void loop()
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
uint8_t hue
Definition advanced.h:94
static Config CreateInmp441(int pin_ws, int pin_sd, int pin_clk, AudioChannel channel, u16 sample_rate=44100ul, int i2s_num=0) FL_NOEXCEPT
Definition input.h:153
void fadeToBlackBy(CRGB *leds, fl::u16 num_leds, fl::u8 fadeBy)
void fill_solid(CRGB *targetArray, int numToFill, const CRGB &color) FL_NOEXCEPT
Fill a range of LEDs with a solid color.
Definition fill.cpp.hpp:9
constexpr EOrder GRB
Definition eorder.h:19
fl::hsv8 CHSV
Definition chsv.h:11
fl::CRGB CRGB
Definition crgb.h:25
@ White
<div style='background:#FFFFFF;width:4em;height:4em;'></div>
Definition crgb.h:646
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:510
#define Serial
Definition serial.h:304