I am trying to make APA102 LED Strip react to music from SD card (.wav) in Teensy Audio Shield.
I am trying it for 4 days. But I am unable. Someone please help me with the code.
/*
#include <FastLED.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>
#define NUM_LEDS 60
#define DATA_PIN 3
#define CLOCK_PIN 13
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14
AudioPlaySdWav playSdWav1;
AudioOutputI2S i2s1;
AudioConnection patchCord1(playSdWav1, 0, i2s1, 0);
AudioConnection patchCord2(playSdWav1, 1, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1;
Bounce button0 = Bounce(0, 15);
Bounce button2 = Bounce(2, 15); // 15 = 15 ms debounce time
CRGB leds[NUM_LEDS];
void setup() {
Serial.begin(9600);
AudioMemory(8);
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);
}
}
FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, BGR>(leds, NUM_LEDS);
pinMode(0, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
}
int filenumber = 0; // while file to play
const char * filelist[4] = {
"SDTEST1.WAV", "SDTEST2.WAV", "SDTEST3.WAV", "SDTEST4.WAV"
};
void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds.nscale8(250); } }
void loop() {
if (playSdWav1.isPlaying() == false)
{
const char *filename = filelist[filenumber];
filenumber = filenumber + 1;
if (filenumber >= 4) filenumber = 0;
Serial.print("Start playing ");
Serial.println(filename);
playSdWav1.play(filename);
delay(10); // wait for library to parse WAV info
}
// read pushbuttons
button0.update();
if (button0.fallingEdge()) {
playSdWav1.stop();
}
button2.update();
if (button2.fallingEdge()) {
playSdWav1.stop();
filenumber = filenumber - 2;
if (filenumber < 0) filenumber = filenumber + 4;
}
// read the knob position (analog input A2)
int knob = analogRead(A2);
float vol = (float)knob / 1280.0;
Serial.print("Volume");
Serial.print("LED ");
//fadeall();
FastLED.show();
sgtl5000_1.volume(vol);
}
*/
I am trying it for 4 days. But I am unable. Someone please help me with the code.
/*
#include <FastLED.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>
#define NUM_LEDS 60
#define DATA_PIN 3
#define CLOCK_PIN 13
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14
AudioPlaySdWav playSdWav1;
AudioOutputI2S i2s1;
AudioConnection patchCord1(playSdWav1, 0, i2s1, 0);
AudioConnection patchCord2(playSdWav1, 1, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1;
Bounce button0 = Bounce(0, 15);
Bounce button2 = Bounce(2, 15); // 15 = 15 ms debounce time
CRGB leds[NUM_LEDS];
void setup() {
Serial.begin(9600);
AudioMemory(8);
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);
}
}
FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, BGR>(leds, NUM_LEDS);
pinMode(0, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
}
int filenumber = 0; // while file to play
const char * filelist[4] = {
"SDTEST1.WAV", "SDTEST2.WAV", "SDTEST3.WAV", "SDTEST4.WAV"
};
void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds.nscale8(250); } }
void loop() {
if (playSdWav1.isPlaying() == false)
{
const char *filename = filelist[filenumber];
filenumber = filenumber + 1;
if (filenumber >= 4) filenumber = 0;
Serial.print("Start playing ");
Serial.println(filename);
playSdWav1.play(filename);
delay(10); // wait for library to parse WAV info
}
// read pushbuttons
button0.update();
if (button0.fallingEdge()) {
playSdWav1.stop();
}
button2.update();
if (button2.fallingEdge()) {
playSdWav1.stop();
filenumber = filenumber - 2;
if (filenumber < 0) filenumber = filenumber + 4;
}
// read the knob position (analog input A2)
int knob = analogRead(A2);
float vol = (float)knob / 1280.0;
Serial.print("Volume");
Serial.print("LED ");
//fadeall();
FastLED.show();
sgtl5000_1.volume(vol);
}
*/