#define USE_OCTOWS2811
#include <OctoWS2811.h>
#include <Audio.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
const unsigned int matrix_width = 60;
const unsigned int matrix_height = 32;
const unsigned int myColor = 0x400020;
const float maxLevel = 0.5;
const float dynamicRange = 40.0;
const float linearBlend = 0.3;
CRGB leds[matrix_width * matrix_height];
AudioInputAnalog adc1(A3);
AudioAnalyzeFFT1024 fft;
AudioConnection patchCord1(adc1, fft);
float thresholdVertical[matrix_height];
int frequencyBinsHorizontal[matrix_width] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 3,
3, 3, 3, 3, 4, 4, 4, 4, 4, 5,
5, 5, 6, 6, 6, 7, 7, 7, 8, 8,
9, 9, 10, 10, 11, 12, 12, 13, 14, 15,
15, 16, 17, 18, 19, 20, 22, 23, 24, 25
};
void setup() {
AudioMemory(12);
computeVerticalLevels();
}
unsigned int xy(unsigned int x, unsigned int y) {
if ((y & 1) == 0) {
return y * matrix_width + x;
} else {
return y * matrix_width + matrix_width - 1 - x;
}
}
void loop() {
unsigned int x, y, freqBin;
float level;
if (fft.available()) {
freqBin = 0;
for (x=0; x < matrix_width; x++) {
level = fft.read(freqBin, freqBin + frequencyBinsHorizontal[x] - 1);
for (y=0; y < matrix_height; y++) {
if (level >= thresholdVertical[y]) {
leds[xy(x,y)] =
CRGB(myColor);
} else {
}
}
freqBin = freqBin + frequencyBinsHorizontal[x];
}
}
}
void computeVerticalLevels() {
unsigned int y;
float n, logLevel, linearLevel;
for (y=0; y < matrix_height; y++) {
n = (float)y / (float)(matrix_height - 1);
logLevel = pow10f(n * -1.0 * (dynamicRange / 20.0));
linearLevel = 1.0 - n;
linearLevel = linearLevel * linearBlend;
logLevel = logLevel * (1.0 - linearBlend);
thresholdVertical[y] = (logLevel + linearLevel) * maxLevel;
}
}
CFastLED FastLED
Global LED strip management instance.
central include file for FastLED, defines the CFastLED class/object
void show(uint8_t scale)
Update all our controllers with the current led colors, using the passed in brightness.
static CLEDController & addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a CLEDController instance to the world.
Representation of an RGB pixel (Red, Green, Blue)