Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #include <elapsedMillis.h>
- #include <Audio.h>
- #include <Wire.h>
- #include <SPI.h>
- #include <SD.h>
- #include <SerialFlash.h>
- #define SDCARD_CS_PIN 10
- #define SDCARD_MOSI_PIN 7
- #define SDCARD_SCK_PIN 14
- #define LED_PIN 8
- #define NUM_LEDS 20
- #define BRIGHTNESS 255
- #define LED_TYPE WS2811
- #define COLOR_ORDER GRB
- AudioPlaySdWav wavPlayer;
- AudioAnalyzeFFT1024 myFFT;
- AudioAnalyzePeak peak;
- AudioMixer4 mixer;
- AudioOutputI2S audioOutput;
- AudioConnection patchCord1(wavPlayer, 0, mixer, 0);
- AudioConnection patchCord2(wavPlayer, 0, audioOutput, 0);
- AudioConnection patchCord3(wavPlayer, 1, mixer, 1);
- AudioConnection patchCord4(wavPlayer, 1, audioOutput, 1);
- AudioConnection patchCord5(mixer, peak);
- AudioConnection patchCord6(mixer, myFFT);
- AudioControlSGTL5000 sgtl5000_1;
- boolean isPlaying = false;
- float currentPeak = 0.0;
- float frequencyBands[3];
- int numPeaks = 2;
- CRGB leds[NUM_LEDS];
- int current = 0;
- CRGBPalette16 palette;
- TBlendType currentBlending;
- elapsedMillis rms;
- elapsedMillis fps;
- void setup() {
- AudioMemory(12);
- sgtl5000_1.enable();
- sgtl5000_1.volume(0.25);
- delay(1000);
- 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);
- }
- }
- FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
- FastLED.setBrightness( BRIGHTNESS );
- }
- void playFile(char *filename){
- wavPlayer.play(filename);
- }
- void checkAudio(){
- if(rms > 30){
- if(peak.available()){
- rms=0;
- currentPeak = peak.read();
- }
- }
- if(myFFT.available()){
- frequencyBands[0] = myFFT.read(0, 10)*255;
- frequencyBands[1] = myFFT.read(6, 32)*210;
- frequencyBands[2] = myFFT.read(16, 360)*30;
- }
- int rOut = (int) frequencyBands[0];
- rOut = min(rOut, 255);
- int gOut = (int) frequencyBands[1];
- gOut = min(gOut, 255);
- int bOut = (int) frequencyBands[2];
- bOut = min(bOut, 255);
- pushToLEDs(currentPeak, rOut, gOut, bOut);
- }
- void pushToLEDs(float currentPeak, int r, int g, int b){
- int numberOfLEDs = (int) (currentPeak*(NUM_LEDS+.1));
- for(int i=0; i<NUM_LEDS/2; i++){
- if(i<currentPeak){
- leds[NUM_LEDS/2+i]=CRGB(r,g,b);
- leds[NUM_LEDS/2-i]=CRGB(r,g,b);
- }
- }
- }
- void updateLEDs(){
- blur1d(leds, NUM_LEDS, 100);
- FastLED.show();
- fadeToBlackBy(leds, NUM_LEDS, 25);
- }
- void loop() {
- if(!isPlaying){
- delay(1000);
- playFile("MOON.wav");
- isPlaying = true;
- }
- checkAudio();
- updateLEDs();
- }
Advertisement
Add Comment
Please, Sign In to add comment