nicodron
Published

FFT spectrum NeoPixel 8×8

Luces audio rítmicas ante intensidad y frecuencias.

IntermediateFull instructions provided70
FFT spectrum NeoPixel 8×8

Things used in this project

Hardware components

General Purpose Dual Op-Amp
Texas Instruments General Purpose Dual Op-Amp
×1
RGB LED Pixel Matrix, NeoPixel NeoMatrix
RGB LED Pixel Matrix, NeoPixel NeoMatrix
×1
Arduino Nano R3
Arduino Nano R3
×1
Microphone, Cartridge
Microphone, Cartridge
×1

Story

Read more

Schematics

diagrama del circuito

Code

Spectrum FFT RGB NeoPixel

Arduino
/* Uso de la librería para usar una matrix Neopixel 8×8 **/
#include <Adafruit_NeoPixel.h>
int Candidad_LEDs = 128; int Brillo_LEDs = 2; int PIN_LEDs = 2;
Adafruit_NeoPixel LEDs = Adafruit_NeoPixel(Candidad_LEDs, PIN_LEDs, NEO_GRB + NEO_KHZ800);

#include "arduinoFFT.h"
const byte Muestras = 64;
const int Muestreo = 10000;

arduinoFFT FFT = arduinoFFT();
double vReal[Muestras];
double vImag[Muestras];
byte Band[Muestras];

unsigned int T_Muestreo;
unsigned long microseg;

void setup() {
  T_Muestreo = round(1000000*(1.0/Muestreo));
  Serial.begin(115200);
  LEDs.begin();                       // inicializacion de la matriz de neopixeles
  LEDs.setBrightness(Brillo_LEDs);    // brillo global para todos los LEDs
}

void loop() {  
  /*SAMPLING*/
  microseg = micros();
  for(int i=0; i<Muestras; i++)
  {
      vReal[i] = analogRead(A0);
      vImag[i] = 0;
      while(micros() - microseg < T_Muestreo){};
      microseg += T_Muestreo;
  }
  
  FFT.Windowing(vReal, Muestras, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
  FFT.Compute(vReal, vImag, Muestras, FFT_FORWARD);
  FFT.ComplexToMagnitude(vReal, vImag, Muestras);

  for (byte i=1; i<=8; i++) {
    Serial.println(vReal[Muestras/2-i]);
  }

// Ecualizador de bandas de frecuencia de la más grave a la más aguda
  Band[1] = map(vReal[Muestras/2-1], 0, 2700, 0, 255);
  Band[2] = map(vReal[Muestras/2-2], 0, 2500, 0, 255);
  Band[3] = map(vReal[Muestras/2-3], 0, 2000, 0, 255);
  Band[4] = map(vReal[Muestras/2-4], 0, 2900, 0, 255);
  Band[5] = map(vReal[Muestras/2-5], 0, 2500, 0, 255);
  Band[6] = map(vReal[Muestras/2-6], 0, 3000, 0, 255);
  Band[7] = map(vReal[Muestras/2-7], 0, 2700, 0, 255);
  Band[8] = map(vReal[Muestras/2-8], 0, 2500, 0, 255);

// Columnas led de izquierda a derecha
  LEDs.clear();
  ColumnaLED(7, Band[1]);
  ColumnaLED(6, Band[2]);
  ColumnaLED(5, Band[3]);
  ColumnaLED(4, Band[4]);
  ColumnaLED(3, Band[5]);
  ColumnaLED(2, Band[6]);
  ColumnaLED(1, Band[7]);
  ColumnaLED(0, Band[8]);
  LEDs.show();
}

/* Funciones NeoPixel para los LEDs */
void ColumnaLED(byte Columna, byte R){
  byte AlturaColumnaLED = map(R, 0, 255, 0, 8);
  for (byte i=0; i <= AlturaColumnaLED; i++){
    LEDs.setPixelColor(Columna + 8*i, R, 255-R, 0);
  }
}

Credits

nicodron

nicodron

0 projects • 0 followers

Comments