//#include <ILI9341_t3.h>
#include <ILI9341_t3DMA.h>
#include <font_Arial.h> // from ILI9341_t3
// include the SD library:
#include <SD.h>
#include <SPI.h>
const int chipSelect = BUILTIN_SDCARD;
#include <Audio.h>
#include <Wire.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioPlaySdWav playSdWav1; //xy=154.66665649414062,158.66666412353516
AudioAnalyzePeak peak1; //xy=398.6666564941406,215.66666412353516
AudioAnalyzePeak peak2; //xy=404.6666564941406,290.66666412353516
AudioOutputUSB usb1; //xy=446.6666564941406,159.66666412353516
AudioConnection patchCord1(playSdWav1, 0, peak1, 0);
AudioConnection patchCord2(playSdWav1, 0, usb1, 0);
AudioConnection patchCord3(playSdWav1, 1, peak2, 0);
AudioConnection patchCord4(playSdWav1, 1, usb1, 1);
//AudioControlSGTL5000 sgtl5000_1; //xy=166.66665649414062,309.66666412353516
AudioOutputI2S out1; // if I don't have this, it won't work at all. Bug or feature?
// GUItool: end automatically generated code
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 255 // 255 = unused, connect to 3.3V
#define TFT_MOSI 11
#define TFT_SCLK 13
#define TFT_MISO 12
//ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);
ILI9341_t3DMA tft = ILI9341_t3DMA(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);
void setup() {
//Serial.begin(9600);
//delay(500);
tft.begin();
tft.dfillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_YELLOW);
//tft.setFont(Arial_24);
//tft.setTextSize(3);
tft.setCursor(40, 8);
tft.println("Peak Meter");
tft.refreshOnce();
AudioMemory(10);
//sgtl5000_1.enable();
//sgtl5000_1.volume(0.5);
//SPI.setMOSI(7);
//SPI.setSCK(14);
if (!(SD.begin(chipSelect))) {
while (1) {
//Serial.println("Unable to access the SD card");
delay(500);
}
}
delay(1000);
}
elapsedMillis msecs;
void loop() {
if (playSdWav1.isPlaying() == false) {
//Serial.println("Start playing");
//playSdWav1.play("SDTEST1.WAV");
//playSdWav1.play("SDTEST2.WAV");
playSdWav1.play("SDTEST5.WAV");
//playSdWav1.play("SDTEST4.WAV");
delay(10); // wait for library to parse WAV info
}
//msecs = 0;
if (msecs > 15) {
if (peak1.available() && peak2.available()) {
msecs = 0;
float leftNumber = peak1.read();
float rightNumber = peak2.read();
//Serial.print(leftNumber);
//Serial.print(", ");
//Serial.print(rightNumber);
//Serial.println();
// draw the verticle bars
int height = leftNumber * 240;
tft.dfillRect(60, 280 - height, 40, height, ILI9341_GREEN);
tft.dfillRect(60, 280 - 240, 40, 240 - height, ILI9341_BLACK);
height = rightNumber * 240;
tft.dfillRect(140, 280 - height, 40, height, ILI9341_GREEN);
tft.dfillRect(140, 280 - 240, 40, 240 - height, ILI9341_BLACK);
// a smarter approach would redraw only the changed portion...
// draw numbers underneath each bar
//tft.setFont(Arial_14);
tft.dfillRect(60, 284, 40, 16, ILI9341_BLACK);
tft.setCursor(60, 284);
tft.print(leftNumber);
tft.dfillRect(140, 284, 40, 16, ILI9341_BLACK);
tft.setCursor(140, 284);
tft.print(rightNumber);
//AudioNoInterrupts();
tft.refreshOnce();
//AudioInterrupts();
}
}
}