|
-
-
- #include <Audio.h>
- #include <ILI9341_t3.h>
- #include <SD.h>
- #include <SerialFlash.h>
- #include <SPI.h>
- #include <Wire.h>
-
-
- #define TFT_DC 20
- #define TFT_CS 21
- #define TFT_RST 255
- #define TFT_MOSI 7
- #define TFT_SCLK 14
- #define TFT_MISO 12
-
- ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);
-
- AudioInputI2S i2s1;
- AudioOutputI2S i2s2;
- AudioAnalyzeFFT1024 fft1024_1;
- AudioConnection patchCord5(i2s1, 0, i2s2, 0);
- AudioConnection patchCord6(i2s1, 0, i2s2, 1);
- AudioConnection patchCord7(i2s1, fft1024_1);
- AudioControlSGTL5000 sgtl5000_1;
-
- static int count = 0;
- static uint16_t line_buffer[320];
- static float scale = 10.0;
- static int knob = 0;
- static int vol = 0;
-
- void setup(void) {
-
- tft.begin();
- tft.fillScreen(ILI9341_BLACK);
- tft.setTextColor(ILI9341_YELLOW);
- tft.setTextSize(2);
-
- AudioMemory(20);
- sgtl5000_1.enable();
- sgtl5000_1.volume(0.5);
- sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
- sgtl5000_1.micGain(36);
-
-
-
-
-
-
- tft.println("Waterfall Spectrum");
- tft.println("adapted from");
- tft.println("Nathaniel Quillin");
- tft.println("SuperCon Badge Hack");
- for (int i = 0; i < 100; i++) {
- tft.setScroll(count++);
- count = count % 320;
- delay(12);
- }
- tft.setRotation(0);
- }
-
- void loop() {
- knob = analogRead(A2);
- vol = analogRead(A3);
-
- scale = 1024 - knob;
- sgtl5000_1.micGain((1024 - vol) / 4);
-
- 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);
- }
-
|