FastLED 3.9.15
Loading...
Searching...
No Matches
Audio.ino
Go to the documentation of this file.
1
4
5// @filter: (mem is large) and ((platform is teensy) or (platform is esp32))
6
7#include <FastLED.h>
8
9#if defined(FL_IS_TEENSY)
10// Keep fbuild's library scanner aware of PJRC Audio sources for Teensy.
11#include <Audio.h>
12#endif
13
14#if !SKETCH_HAS_LARGE_MEMORY
15void setup() {}
16void loop() {}
17#else
18
19#include "fl/ui/ui.h"
20
21#define NUM_LEDS 180
22#define LEDS_PER_SEGMENT 60
23#define DATA_PIN 3
24
26fl::UIAudio audio_ui("Audio Input");
27
28void setup() {
29 Serial.begin(115200);
30 FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
31 FastLED.setBrightness(128);
32}
33
34void loop() {
36
37 // Lazily registers with FastLED on first call, cached thereafter
38 auto audio = audio_ui.processor();
39
40 float bass = audio->getVibeBass();
41 float mid = audio->getVibeMid();
42 float treb = audio->getVibeTreb();
43
44 // Segment 1 (LEDs 0-59): Bass - red/orange
45 uint8_t bassVal = fl::clamp(bass * 200.0f, 0.0f, 255.0f);
46 fill_solid(leds, LEDS_PER_SEGMENT, CHSV(0, 255, bassVal));
47
48 // Segment 2 (LEDs 60-119): Mid - green
49 uint8_t midVal = fl::clamp(mid * 200.0f, 0.0f, 255.0f);
50 fill_solid(leds + LEDS_PER_SEGMENT, LEDS_PER_SEGMENT, CHSV(96, 255, midVal));
51
52 // Segment 3 (LEDs 120-179): Treble - blue
53 uint8_t trebVal = fl::clamp(treb * 200.0f, 0.0f, 255.0f);
54 fill_solid(leds + 2 * LEDS_PER_SEGMENT, LEDS_PER_SEGMENT, CHSV(160, 255, trebVal));
55
56 FastLED.show();
57}
58
59#endif
void setup()
void loop()
fl::UIAudio audio("Audio Input")
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
#define DATA_PIN
Definition ClientReal.h:82
fl::UIAudio audio_ui("Audio Input")
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
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
constexpr enable_if< is_fixed_point< T >::value, T >::type clamp(T x, T lo, T hi) FL_NOEXCEPT
unsigned char uint8_t
Definition s16x16x4.h:209
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38
#define Serial
Definition serial.h:304
Aggregator header for the fl/ui/ family of per-element UI types.