#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <FastLED.h>
#define LED_TYPE WS2812B
#define COLOR_ORDER BGR
#define NUM_LEDS 296
#define DATA_PIN 10
CRGB leds[NUM_LEDS];
#define BRIGHTNESS 40
#define FRAMES_PER_SECOND 120
uint8_t hue = 15;
//uint8_t level[144];
uint8_t oldLevel[144];
uint8_t value[144];
float rawValue[144];
float scale = 500.0;
float level[16];
int shown[16];
// GUItool: begin automatically generated code
AudioInputAnalog adc1(A0); //xy=179,182
AudioAnalyzeFFT1024 fft1024_1; //xy=401,185
AudioConnection patchCord1(adc1, fft1024_1);
// GUItool: end automatically generated code
void setup() {
//IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_02 &= ~ (1<<12) ; // disable keeper
AudioMemory(12);
fft1024_1.windowFunction(AudioWindowHanning1024);
delay(100);
FastLED.addLeds<1, WS2812B, 10, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
pinMode(10, OUTPUT);
}
void loop() {
if(fft1024_1.available()){
level[0] = fft1024_1.read(0);
level[1] = fft1024_1.read(1);
level[2] = fft1024_1.read(2, 3);
level[3] = fft1024_1.read(4, 6);
level[4] = fft1024_1.read(7, 10);
level[5] = fft1024_1.read(11, 15);
level[6] = fft1024_1.read(16, 22);
level[7] = fft1024_1.read(23, 32);
level[8] = fft1024_1.read(33, 46);
level[9] = fft1024_1.read(47, 66);
level[10] = fft1024_1.read(67, 93);
level[11] = fft1024_1.read(94, 131);
level[12] = fft1024_1.read(132, 184);
level[13] = fft1024_1.read(185, 257);
level[14] = fft1024_1.read(258, 359);
level[15] = fft1024_1.read(360, 511);
hue = 20;
for(int i=0; i<16; i++){
int val = level[i] * scale;
if(val > 255) val = 255;
if(val >= shown[i]) {
shown[i] = val;
} else {
if (shown[i] > 6) shown[i] = shown[i] -7;
val = shown[i];
}
if(shown[i] == 0) {
leds[i] = CRGB::Black;
} else {
leds[i*3] = CHSV(hue, 255, shown[i]-1);
leds[(i*3)-1] = CHSV(hue, 255, shown[i]-1);
leds[(i*3)+1] = CHSV(hue, 255, shown[i]-1);
hue = hue + 15;
}
}
FastLED.show();
} //end FFT-available
}