From 3f94db84fa38ea9ca1e2772823331f7602ac17a9 Mon Sep 17 00:00:00 2001 From: Alderon Date: Thu, 1 May 2025 21:46:29 +1000 Subject: [PATCH 1/2] Fix FFT object creation to be in line with modern usage; Fix calls to FFT arguements that were incorrectly capitalised; define LED matrix setup for WS2812B strip --- ...Visualizer.ino => LED-Audio-Visualizer.ino | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) rename FFT_Visualizer.ino => LED-Audio-Visualizer.ino (62%) diff --git a/FFT_Visualizer.ino b/LED-Audio-Visualizer.ino similarity index 62% rename from FFT_Visualizer.ino rename to LED-Audio-Visualizer.ino index 581af1b..e0dc5a3 100644 --- a/FFT_Visualizer.ino +++ b/LED-Audio-Visualizer.ino @@ -4,65 +4,66 @@ #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 LED_TYPE WS2812B +#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]; +const uint16_t samples = 64; +const float samplingFrequency = 5000; 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 FFT = ArduinoFFT(vReal, vImag, SAMPLES, SAMPLE_FREQ); // Create FFT object void setup() { pinMode(MIC_IN, INPUT); Serial.begin(115200); //Initialize Serial delay(3000); // power-up safety delay - FastLED.addLeds(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); //Initialize LED strips + FastLED.addLeds(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); //Initialize LED strips FastLED.setCorrection(TypicalSMD5050); FastLED.setBrightness(BRIGHTNESS); } 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]; } } From fb4846c671be51bc46fd8e1007de6811be8e309f Mon Sep 17 00:00:00 2001 From: SirMew Date: Sat, 5 Jul 2025 13:14:29 +1000 Subject: [PATCH 2/2] Clean up for pull request Removed unused debugging variables. Replace dark implementation of brightness with value of 0x000000 (black). --- LED-Audio-Visualizer.ino | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/LED-Audio-Visualizer.ino b/LED-Audio-Visualizer.ino index e0dc5a3..f0538bc 100644 --- a/LED-Audio-Visualizer.ino +++ b/LED-Audio-Visualizer.ino @@ -6,7 +6,7 @@ #define LED_PIN 2 // Data pin to LEDS #define NUM_LEDS 16*16 #define BRIGHTNESS 150 // LED information -#define LED_TYPE WS2812B +#define LED_TYPE WS2811 #define SAMPLE_FREQ 5000 #define COLOR_ORDER GRB #define BUTTON_PIN 3 @@ -15,8 +15,6 @@ float vReal[SAMPLES]; float vImag[SAMPLES]; -const uint16_t samples = 64; -const float samplingFrequency = 5000; int Intensity[xres] = { }; // initialize Frequency Intensity to zero int displacement = 1; @@ -29,7 +27,7 @@ void setup() { pinMode(MIC_IN, INPUT); Serial.begin(115200); //Initialize Serial delay(3000); // power-up safety delay - FastLED.addLeds(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); //Initialize LED strips FastLED.setCorrection(TypicalSMD5050); + FastLED.addLeds(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); //Initialize LED strips FastLED.setBrightness(BRIGHTNESS); } @@ -81,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; } } }