FastLED 3.9.15
Loading...
Searching...
No Matches

◆ drawVUMeter()

void drawVUMeter ( float rms,
float peak )

Definition at line 341 of file advanced.h.

341 {
342 clearDisplay();
343 fl::CRGBPalette16 palette = getCurrentPalette();
344
345 // RMS level bar
346 int rmsWidth = rms * WIDTH * audioGain.value() * autoGainValue;
347 rmsWidth = fl::min(rmsWidth, WIDTH);
348
349 for (int x = 0; x < rmsWidth; x++) {
350 for (int y = HEIGHT/3; y < 2*HEIGHT/3; y++) {
351 uint8_t colorIndex = fl::map_range<int, uint8_t>(x, 0, WIDTH, 0, 255);
352 int ledIndex = xyMap(x, y);
353 if (ledIndex >= 0 && ledIndex < NUM_LEDS) {
354 leds[ledIndex] = ColorFromPalette(palette, colorIndex);
355 }
356 }
357 }
358
359 // Peak indicator
360 int peakX = peak * WIDTH * audioGain.value() * autoGainValue;
361 peakX = fl::min(peakX, WIDTH - 1);
362
363 for (int y = HEIGHT/4; y < 3*HEIGHT/4; y++) {
364 int ledIndex = xyMap(peakX, y);
365 if (ledIndex >= 0 && ledIndex < NUM_LEDS) {
366 leds[ledIndex] = fl::CRGB::White;
367 }
368 }
369
370 // Beat indicator
371 if (isBeat && beatFlash) {
372 for (int x = 0; x < WIDTH; x++) {
373 int ledIndex1 = xyMap(x, 0);
374 int ledIndex2 = xyMap(x, HEIGHT - 1);
375 if (ledIndex1 >= 0 && ledIndex1 < NUM_LEDS) leds[ledIndex1] = fl::CRGB::White;
376 if (ledIndex2 >= 0 && ledIndex2 < NUM_LEDS) leds[ledIndex2] = fl::CRGB::White;
377 }
378 }
379}
fl::XYMap xyMap
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
int y
Definition simple.h:93
float rms(fl::span< const int16_t > data)
Definition simple.h:104
int x
Definition simple.h:92
UINumberField palette("Palette", 0, 0, 2)
bool isBeat
Definition advanced.h:89
#define WIDTH
fl::CRGBPalette16 getCurrentPalette()
Definition advanced.h:109
float autoGainValue
Definition advanced.h:90
fl::UISlider audioGain("Audio Gain", 1.0f, 0.1f, 5.0f, 0.1f)
fl::UICheckbox beatFlash("Beat Flash", true)
#define HEIGHT
void clearDisplay()
Definition advanced.h:173
CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType)
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
Definition math.h:71
FASTLED_FORCE_INLINE U map_range(T value, T in_min, T in_max, U out_min, U out_max) FL_NOEXCEPT
Definition math.h:174
unsigned char uint8_t
Definition s16x16x4.h:209
@ White
<div style='background:#FFFFFF;width:4em;height:4em;'></div>
Definition crgb.h:646

References audioGain(), autoGainValue, beatFlash(), clearDisplay(), ColorFromPalette(), getCurrentPalette(), HEIGHT, isBeat, leds, fl::map_range(), fl::min(), NUM_LEDS, palette(), rms(), fl::CRGB::White, WIDTH, x, xyMap, and y.

Referenced by loop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: