-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
// This example requires the use of https://github.com/stnkl/FastLEDHub_AudioViz to send | ||
// spectrum data to the ESP32/ESP8266 running FastLEDHub. | ||
|
||
#include <FastLEDHub.h> | ||
|
||
#include <math.h> | ||
|
||
extern CRGB leds[]; | ||
|
||
class Spectrogram : public Animation | ||
{ | ||
public: | ||
using Animation::Animation; | ||
|
||
uint8_t interpolateSpectrum(uint16_t led) | ||
{ | ||
float stepSize = (float)(SPECTRUM_LENGTH - 1) / ((float)FastLEDHub.size() - 1); | ||
float spectrumPosition = led * stepSize; | ||
int16_t spectrumFloorIndex = (int16_t)spectrumPosition % SPECTRUM_LENGTH; | ||
int16_t spectrumFloor = FastLEDHub.spectrumData[spectrumFloorIndex]; | ||
int16_t spectrumCeil = FastLEDHub.spectrumData[(spectrumFloorIndex + 1) % SPECTRUM_LENGTH]; | ||
uint8_t intensity = spectrumFloor + fmod(spectrumPosition, 1) * (spectrumCeil - spectrumFloor); | ||
return intensity; | ||
} | ||
|
||
void reset() | ||
{ | ||
} | ||
|
||
void loop() | ||
{ | ||
for (uint16_t i = 0; i < FastLEDHub.size(); i++) | ||
{ | ||
CRGB color = CRGB::White; | ||
leds[i] = color.nscale8(interpolateSpectrum(i)); | ||
} | ||
|
||
FastLEDHub.show(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <FastLEDHub.h> | ||
|
||
#include "Animations/Spectrogram.h" | ||
|
||
#define NUM_LEDS 100 | ||
#define LIGHTSTRIP_PIN 5 | ||
#define LED_TYPE WS2812B | ||
|
||
CRGB leds[NUM_LEDS]; | ||
|
||
void setup() | ||
{ | ||
FastLEDHub.initialize("Spectrogram Example"); | ||
FastLEDHub.addLeds<LED_TYPE, LIGHTSTRIP_PIN, GRB>(leds, NUM_LEDS); | ||
|
||
FastLEDHub.registerAnimation(new Spectrogram("Spectrogram")); | ||
} | ||
|
||
void loop() | ||
{ | ||
FastLEDHub.handle(); | ||
} |