#include <Audio.h>
#include <Wire.h>
#include "SPI.h"
#include <ILI9341_t3n.h>
#define TFT_RST 255
#define TFT_DC 9
#define TFT_CS 10
static int count = 0;
static uint16_t line_buffer[320];
static float scale = 10.0;
ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST);
// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=233,172
AudioMixer4 mixer1; //xy=433,245
AudioOutputI2S i2s2; //xy=434,173
AudioAnalyzeFFT1024 fft1024_1; //xy=583,245
AudioConnection patchCord1(i2s1, 0, mixer1, 0);
AudioConnection patchCord2(i2s1, 0, i2s2, 0);
AudioConnection patchCord3(i2s1, 1, mixer1, 1);
AudioConnection patchCord4(i2s1, 1, i2s2, 1);
AudioConnection patchCord5(mixer1, fft1024_1);
AudioControlSGTL5000 sgtl5000_1; //xy=245,262
// GUItool: end automatically generated code
void setup(void) {
AudioMemory(20);
sgtl5000_1.enable();
sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
sgtl5000_1.volume(.5);
tft.begin(50000000);
tft.setRotation(2);
tft.fillScreen(ILI9341_WHITE);
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setTextSize(2);
tft.setCursor(0, 0);
tft.print("TEST");
}
void loop() {
if (fft1024_1.available()) {
for (int i = 0; i < 240; i++) {
line_buffer[240 - i - 1] = colorMap(fft1024_1.output[i]);
}
tft.writeRect(0, count, 240, 1, (uint16_t*)&line_buffer);
tft.setScroll(count++);
count = count % 320;
}
}
uint16_t colorMap(uint16_t val) {
float red;
float green;
float blue;
float temp = val / 65536.0 * scale;
if (temp < 0.5) {
red = 0.0;
green = temp * 2;
blue = 2 * (0.5 - temp);
}
else {
red = temp;
green = (1.0 - temp);
blue = 0.0;
}
return tft.color565(red * 256, green * 256, blue * 256);
}