Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_GFX.h>
- #include <Adafruit_NeoMatrix.h>
- #include <Adafruit_NeoPixel.h>
- #define PIN 3
- Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN,
- NEO_MATRIX_BOTTOM + NEO_MATRIX_LEFT +
- NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
- NEO_GRB + NEO_KHZ800);
- const uint16_t colors[] = {
- matrix.Color(128, 0, 0),
- matrix.Color(255, 0, 0),
- matrix.Color(255, 128, 0),
- matrix.Color(255, 255, 0),
- matrix.Color(0, 255, 0),
- matrix.Color(0, 255, 128),
- matrix.Color(0, 128, 255),
- matrix.Color(0, 0, 255),
- };
- #include <Audio.h>
- #include <Bounce.h>
- Bounce button0 = Bounce(0, 15);
- Bounce button1 = Bounce(1, 15); // 15 = 15 ms debounce time
- Bounce button2 = Bounce(2, 15);
- ///////////////////////////////////
- // copy the Design Tool code here
- ///////////////////////////////////
- #include <Audio.h>
- #include <Wire.h>
- #include <SPI.h>
- #include <SD.h>
- #include <SerialFlash.h>
- // GUItool: begin automatically generated code
- AudioInputI2S i2s2; //xy=210,60
- AudioPlayMemory playMem1; //xy=261,210
- AudioSynthWaveform waveform1; //xy=284,269
- AudioMixer4 mixer1; //xy=450,196
- AudioOutputI2S i2s1; //xy=669,145
- AudioAnalyzeFFT1024 fft1024_1; //xy=677,201
- AudioConnection patchCord1(i2s2, 0, mixer1, 0);
- AudioConnection patchCord2(i2s2, 1, mixer1, 1);
- AudioConnection patchCord3(playMem1, 0, mixer1, 2);
- AudioConnection patchCord4(waveform1, 0, mixer1, 3);
- AudioConnection patchCord5(mixer1, 0, i2s1, 0);
- AudioConnection patchCord6(mixer1, 0, i2s1, 1);
- AudioConnection patchCord7(mixer1, fft1024_1);
- AudioControlSGTL5000 sgtl5000_1; //xy=526,301
- // GUItool: end automatically generated code
- // Use these with the Teensy Audio Shield
- #define SDCARD_CS_PIN 10
- #define SDCARD_MOSI_PIN 7
- #define SDCARD_SCK_PIN 14
- // Use these with the Teensy 3.5 & 3.6 SD card
- //#define SDCARD_CS_PIN BUILTIN_SDCARD
- //#define SDCARD_MOSI_PIN 11 // not actually used
- //#define SDCARD_SCK_PIN 13 // not actually used
- // Use these for the SD+Wiz820 or other adaptors
- //#define SDCARD_CS_PIN 4
- //#define SDCARD_MOSI_PIN 11
- //#define SDCARD_SCK_PIN 13
- const int myInput = AUDIO_INPUT_LINEIN;
- void setup() {
- Serial.begin(57600);
- matrix.begin();
- matrix.setTextWrap(false);
- matrix.setBrightness(40);
- matrix.setTextColor(colors[0]);
- matrix.fillScreen(0);
- matrix.show();
- AudioMemory(12);
- sgtl5000_1.enable();
- sgtl5000_1.volume(0.5);
- // SPI.setMOSI(SDCARD_MOSI_PIN);
- // SPI.setSCK(SDCARD_SCK_PIN);
- // if (!(SD.begin(SDCARD_CS_PIN))) {
- // while (1) {
- // Serial.println("Unable to access the SD card");
- // delay(500);
- // }
- // }
- // Enable audio in
- sgtl5000_1.enable();
- sgtl5000_1.inputSelect(myInput);
- sgtl5000_1.volume(1);
- mixer1.gain(0, 1.0);
- mixer1.gain(1, 1.0);
- mixer1.gain(2, 0.0);
- mixer1.gain(3, 0.0);
- // Uncomment one these to try other window functions
- // fft1024_1.windowFunction(NULL);
- // fft1024_1.windowFunction(AudioWindowBartlett1024);
- // fft1024_1.windowFunction(AudioWindowFlattop1024);
- delay(2000);
- //playSdWav1.play("SDTEST2.WAV");
- }
- void loop() {
- if (fft1024_1.available()) {
- spectrum(0,fft1024_1.read(0,1));
- spectrum(1,fft1024_1.read(1,15));
- spectrum(2,fft1024_1.read(16,31));
- spectrum(3,fft1024_1.read(32,47));
- spectrum(4,fft1024_1.read(48,63));
- spectrum(5,fft1024_1.read(64,79));
- spectrum(6,fft1024_1.read(80,95));
- spectrum(7,fft1024_1.read(96,111));
- spectrum(8,fft1024_1.read(112,127));
- spectrum(9,fft1024_1.read(128,143));
- spectrum(10,fft1024_1.read(144,159));
- spectrum(11,fft1024_1.read(160,175));
- spectrum(12,fft1024_1.read(176,191));
- spectrum(13,fft1024_1.read(192,207));
- spectrum(14,fft1024_1.read(208,223));
- spectrum(15,fft1024_1.read(224,239));
- spectrum(16,fft1024_1.read(240,255));
- spectrum(17,fft1024_1.read(256,271));
- spectrum(18,fft1024_1.read(272,287));
- spectrum(19,fft1024_1.read(288,303));
- spectrum(20,fft1024_1.read(304,319));
- spectrum(21,fft1024_1.read(320,335));
- spectrum(22,fft1024_1.read(336,351));
- spectrum(23,fft1024_1.read(352,367));
- spectrum(24,fft1024_1.read(368,383));
- spectrum(25,fft1024_1.read(384,399));
- spectrum(26,fft1024_1.read(400,415));
- spectrum(27,fft1024_1.read(416,432));
- spectrum(28,fft1024_1.read(433,447));
- spectrum(29,fft1024_1.read(448,463));
- spectrum(30,fft1024_1.read(464,479));
- spectrum(31,fft1024_1.read(480,4511));
- matrix.show();
- }
- matrix.fillScreen(0);
- delay(10);
- matrix.show();
- }
- void spectrum(int x, float n) {
- // x = band
- // y = led height
- int y = LEDnumber(n);
- matrix.drawPixel(x,y,colors[y]);
- // Serial.print(band);
- // Serial.print(" ");
- // Serial.print(LEDnumber(n));
- // Serial.println();
- }
- int LEDnumber(float n) {
- int led = 0;
- if (n > 0.250) {
- led = 8;
- } else if ( n > 0.220) {
- led = 7;
- } else if ( n > 0.180) {
- led = 6;
- } else if ( n > 0.100) {
- led = 5;
- } else if ( n > 0.060) {
- led = 4;
- } else if ( n > 0.030) {
- led = 3;
- } else if ( n > 0.010) {
- led = 2;
- } else if ( n > 0.008) {
- led = 1;
- } else if ( n < 0.009) {
- led = 0;
- }
- return led;
- }
- //void printNumber(float n) {
- //
- // if (n > 0.25) {
- // Serial.print("##### ");
- // } else if (n > 0.18) {
- // Serial.print(".###. ");
- // } else if (n > 0.06) {
- // Serial.print("..#.. ");
- // } else if (n > 0.005) {
- // Serial.print("..*.. ");
- // } else if ( n < 0.005) {
- // Serial.print("..... ");
- // }
- //
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement