|
- #include <LiquidCrystal.h>
- #include <Audio.h>
- #include <Wire.h>
- #include <SPI.h>
- #include <SD.h>
- #include <SerialFlash.h>
-
-
- AudioInputI2S i2s1;
- AudioMixer4 mixer1;
- AudioOutputI2S i2s2;
- AudioAnalyzeFFT1024 fft1024;
- 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);
- AudioControlSGTL5000 audioShield;
-
-
-
- const int myInput = AUDIO_INPUT_LINEIN;
-
-
-
-
-
- float scale = 60.0;
-
-
- float level[16];
-
-
-
-
- int shown[16];
-
-
-
-
-
- LiquidCrystal lcd(0, 1, 2, 3, 4, 5);
- byte bar1[8] = {0,0,0,0,0,0,0,255};
- byte bar2[8] = {0,0,0,0,0,0,255,255};
- byte bar3[8] = {0,0,0,0,0,255,255,255};
- byte bar4[8] = {0,0,0,0,255,255,255,255};
- byte bar5[8] = {0,0,0,255,255,255,255,255};
- byte bar6[8] = {0,0,255,255,255,255,255,255};
- byte bar7[8] = {0,255,255,255,255,255,255,255};
- byte bar8[8] = {255,255,255,255,255,255,255,255};
-
-
- void setup() {
-
- AudioMemory(12);
-
-
- audioShield.enable();
- audioShield.inputSelect(myInput);
- audioShield.volume(0.5);
-
-
- lcd.begin(16, 2);
- lcd.print("Audio Spectrum");
- lcd.createChar(0, bar1);
- lcd.createChar(1, bar2);
- lcd.createChar(2, bar3);
- lcd.createChar(3, bar4);
- lcd.createChar(4, bar5);
- lcd.createChar(5, bar6);
- lcd.createChar(6, bar7);
- lcd.createChar(7, bar8);
-
-
- mixer1.gain(0, 0.5);
- mixer1.gain(1, 0.5);
-
-
- pinMode(21, INPUT_PULLUP);
- }
-
-
- void loop() {
- if (fft1024.available()) {
-
-
-
-
- level[0] = fft1024.read(0);
- level[1] = fft1024.read(1);
- level[2] = fft1024.read(2, 3);
- level[3] = fft1024.read(4, 6);
- level[4] = fft1024.read(7, 10);
- level[5] = fft1024.read(11, 15);
- level[6] = fft1024.read(16, 22);
- level[7] = fft1024.read(23, 32);
- level[8] = fft1024.read(33, 46);
- level[9] = fft1024.read(47, 66);
- level[10] = fft1024.read(67, 93);
- level[11] = fft1024.read(94, 131);
- level[12] = fft1024.read(132, 184);
- level[13] = fft1024.read(185, 257);
- level[14] = fft1024.read(258, 359);
- level[15] = fft1024.read(360, 511);
-
-
-
-
-
-
-
-
- lcd.setCursor(0, 1);
-
- for (int i=0; i<16; i++) {
- Serial.print(level[i]);
-
-
-
- int val = level[i] * scale;
- if (val > 8) val = 8;
-
- if (val >= shown[i]) {
- shown[i] = val;
- } else {
- if (shown[i] > 0) shown[i] = shown[i] - 1;
- val = shown[i];
- }
-
-
- Serial.print(" ");
-
-
- if (shown[i] == 0) {
- lcd.write(' ');
- } else {
- lcd.write(shown[i] - 1);
- }
- }
- Serial.print(" cpu:");
- Serial.println(AudioProcessorUsageMax());
- }
- }
-
|