What should happen: Using arduinoFFT, serial should print out data computed from microphone sensor. Using Adafruit_Neopixel, light strip should illuminate based on colorWipe function.
What is happening: (1): only the serial data is printed, light strip does not illuminate. OR (2): if I remove FFT.Compute and FFT.ComplexToMagnitude functions from code below, serial prints data (incorrect data b/c of removed functions) and lights illuminate properly.
I can't seem to figure out why FFT.Compute and FFT.ComplexToMagnitude seems to prevent the light strip from illuminating properly. Without those two lines, the lights work as expected. Any guidance appreciated.
Full code below:
#include <arduinoFFT.h>
#include <Adafruit_NeoPixel.h>
#define SAMPLES 128
#define SAMPLING_FREQUENCY 1000
#define PIN 6
#define NUMPIXELS 300
int delayval = 500;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
arduinoFFT FFT = arduinoFFT();
unsigned int sampling_period_us;
unsigned long microseconds;
double vReal[SAMPLES];
double vImag[SAMPLES];
void setup() {
Serial.begin(115200);
sampling_period_us = round(1000000*(1.0/SAMPLING_FREQUENCY));
strip.begin();
strip.show();
}
void loop() {
colorWipe(strip.Color(255, 255, 255));
for(int i=0; i<SAMPLES; i++) {
microseconds = micros();
vReal[i] = analogRead(0);
vImag[i] = 0;
while(micros() < (microseconds + sampling_period_us)){
}
}
FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);
double peak = FFT.MajorPeak(vReal, SAMPLES, SAMPLING_FREQUENCY);
for(int i=0; i<(SAMPLES/2); i++) {
Serial.println(vReal[i], 1);
}
delay(10);
}
void colorWipe(uint32_t c) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(10);
}
}