Hi
I'm working through the audio board tutorial using a Teensy 4 and have stumbled at Part 1 05 'Do More While Playing'.
The code below is a simplification of the 1.05 sketch that isolates the problem - that is: I can either play the sound -or- I can blink. But I can't do both!
If I comment out the
, the sound will play. If I comment out the block starting
the LED will blink, but I cannot play and blink together.
Am I missing something obvious?
I'm working through the audio board tutorial using a Teensy 4 and have stumbled at Part 1 05 'Do More While Playing'.
The code below is a simplification of the 1.05 sketch that isolates the problem - that is: I can either play the sound -or- I can blink. But I can't do both!
If I comment out the
Code:
pinMode(13, OUTPUT); // LED on pin 13
Code:
if (playSdWav1.isPlaying() == false) {...}
Am I missing something obvious?
Code:
// Advanced Microcontroller-based Audio Workshop
//
// http://www.pjrc.com/store/audio_tutorial_kit.html
// https://hackaday.io/project/8292-microcontroller-audio-workshop-had-supercon-2015
//
// Part 1-3: First "Hello World" program, play a music file
//
// WAV files for this and other Tutorials are here:
// http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
AudioPlaySdWav playSdWav1;
AudioOutputI2S i2s1;
AudioConnection patchCord1(playSdWav1, 0, i2s1, 0);
AudioConnection patchCord2(playSdWav1, 1, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1;
// 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
elapsedMillis blinkTime;
void setup() {
Serial.begin(9600);
AudioMemory(8);
sgtl5000_1.enable();
sgtl5000_1.volume(0.2);
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);
}
}
//Comment this line out, audio plays from SD card
pinMode(13, OUTPUT); // LED on pin 13
delay(2000);
}
void loop() {
//Comment this block out and LED will blink.
if (playSdWav1.isPlaying() == false) {
Serial.println("Start playing");
playSdWav1.play("SDTEST2.WAV");
delay(10); // wait for library to parse WAV info
}
// do nothing while playing...
// blink the LED without delays
if (blinkTime < 250) {
digitalWrite(13, LOW);
} else if (blinkTime < 500) {
digitalWrite(13, HIGH);
} else {
blinkTime = 0; // start blink cycle over again
}
}