Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions FFT_Visualizer.ino → LED-Audio-Visualizer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@
#define SAMPLES 64 // Must be a power of 2
#define MIC_IN A0 // Use A0 for mic input
#define LED_PIN 2 // Data pin to LEDS
#define NUM_LEDS 64
#define NUM_LEDS 16*16
#define BRIGHTNESS 150 // LED information
#define LED_TYPE WS2811
#define SAMPLE_FREQ 5000
#define COLOR_ORDER GRB
#define BUTTON_PIN 3
#define xres 8 // Total number of columns in the display
#define yres 8 // Total number of rows in the display
#define xres 16 // Total number of columns in the display
#define yres 16 // Total number of rows in the display

double vReal[SAMPLES];
double vImag[SAMPLES];
float vReal[SAMPLES];
float vImag[SAMPLES];

int Intensity[xres] = { }; // initialize Frequency Intensity to zero
int Displacement = 1;
int displacement = 1;

CRGB leds[NUM_LEDS]; // Create LED Object
arduinoFFT FFT = arduinoFFT(); // Create FFT object

ArduinoFFT<float> FFT = ArduinoFFT<float>(vReal, vImag, SAMPLES, SAMPLE_FREQ); // Create FFT object

void setup() {
pinMode(MIC_IN, INPUT);
Expand All @@ -30,39 +32,36 @@ void setup() {
}

void loop() {
Visualizer();
}

void Visualizer(){
//Collect Samples
getSamples();

//Update Display
//Update display data
displayUpdate();

//Update LEDs with data
FastLED.show();
}

void getSamples(){
for(int i = 0; i < SAMPLES; i++){
vReal[i] = analogRead(MIC_IN);
vReal[i] = analogRead(MIC_IN); //read sample
Serial.println(vReal[i]);
vImag[i] = 0;
}

//FFT
FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);
FFT.windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
FFT.compute(vReal, vImag, SAMPLES, FFT_FORWARD);
FFT.complexToMagnitude(vReal, vImag, SAMPLES);

//Update Intensity Array
for(int i = 2; i < (xres*Displacement)+2; i+=Displacement){
for(int i = 2; i < (xres*displacement)+2; i+=displacement){
vReal[i] = constrain(vReal[i],0 ,2047); // set max value for input data
vReal[i] = map(vReal[i], 0, 2047, 0, yres); // map data to fit our display

Intensity[(i/Displacement)-2] --; // Decrease displayed value
if (vReal[i] > Intensity[(i/Displacement)-2]) // Match displayed value to measured value
Intensity[(i/Displacement)-2] = vReal[i];
Intensity[(i/displacement)-2] --; // Decrease displayed value
if (vReal[i] > Intensity[(i/displacement)-2]) // Match displayed value to measured value
Intensity[(i/displacement)-2] = vReal[i];
}
}

Expand All @@ -80,10 +79,10 @@ void displayUpdate(){
}
else{ // Everything outside the range goes dark
if(j%2 == 0){
leds[(xres*(j+1))-i-1] = CHSV(color, 255, 0);
leds[(xres*(j+1))-i-1] = 0x000000;
}
else{
leds[(xres*j)+i] = CHSV(color, 255, 0);
leds[(xres*j)+i] = 0x000000;
}
}
}
Expand Down