Hello,
I am working on lightsaber using Teensy 3.2 + prop shield and I have a problem playing sounds from SD card when I use FastLED library to drive APA 102 LEDS
I tested LEDS and playing sounds in separate sketches and they work fine.
Below is the code that I am using, commenting/uncommenting indicated lines switches between working LEDS or working sound.
I’m attaching link to schematic of my SD card adapter.
Please can someone help me with this problem?
#include <SPI.h>
// SD CARD =========================
#include <SD.h>
#define CS_pin 10
// SOUND =========================
#include <Audio.h>
#include <SerialFlash.h>
#define AMP 5
#define SOUNDS_VOLUME 0.04f
#define HUM_VOLUME 0.4f
// GUItool: begin automatically generated code
AudioPlaySdWav HUM; //xy=605,422
AudioPlaySdWav SOUNDS; //xy=628,310
AudioMixer4 MIXER; //xy=789,380
AudioOutputAnalog DAC; //xy=939,296
AudioConnection patchCord1(HUM, 0, MIXER, 1);
AudioConnection patchCord2(SOUNDS, 0, MIXER, 0);
AudioConnection patchCord3(MIXER, DAC);
// GUItool: end automatically generated code
// FastLED ============================================
#include <FastLED.h>
#include <SPI.h>
#define NUM_LEDS 288
#define LED_ENABLE 7
CRGB leds[NUM_LEDS];
void setup()
{
SPI.begin();
Serial.begin(9600);
// SD CARD =========================================================
pinMode(SS, OUTPUT);
digitalWrite(SS, HIGH); // deselect SD
if(!SD.begin())//initialize SD card
{
while(1)
{
Serial.println (“Cannot access SPI Flash chip”);
delay (3000);
}
}
// AUDIO ===========================================================
DAC.analogReference(INTERNAL); //INTERNAL OR EXTERNAL → VOLUME
pinMode(AMP,OUTPUT);
digitalWrite(AMP, HIGH); //enable Amplifier
AudioMemory(8); // Audio connections require memory to work.
MIXER.gain(0, SOUNDS_VOLUME); //other sounds
MIXER.gain(1, HUM_VOLUME); //hum
// this also does not work when strip.begin below is uncommented
digitalWrite(SS, LOW);
SOUNDS.play(“beep.wav”);
while(SOUNDS.isPlaying());
digitalWrite(SS, HIGH);
// FastLED =====================================================
// FastLED.addLeds<APA102, BGR>(leds, NUM_LEDS); // Audio stops when uncommented
pinMode(LED_ENABLE, OUTPUT);
}
void loop()
{
// FastLED ===================================================
for(int n = 0; n < NUM_LEDS; n++)
{
leds[n].red = 5;
leds[n].green = 0;
leds[n].blue = 0;
SPI.beginTransaction(SPISettings(24000000, MSBFIRST, SPI_MODE0));
digitalWrite(LED_ENABLE, HIGH);
// FastLED.show(); // Audio stops when uncommented
digitalWrite(LED_ENABLE, LOW);
SPI.endTransaction();
delay(8);
leds[n] = CRGB::Black;
}
// AUDIO =====================================================
digitalWrite(LED_ENABLE, LOW);
digitalWrite(SS, LOW);
SOUNDS.play(“beep.wav”);
while(SOUNDS.isPlaying());
digitalWrite(SS, HIGH);
digitalWrite(LED_ENABLE, HIGH);
delay(1000);
}
Best regards