Hi
I have a MKRZero up and running and am able to play sound files okay.
My problem is that I have to wait for a sound file to finish playing before I can play another one. I am building a radio prop were a user can press buttons to hear different stations. At the moment a particular station has to finish playing before the user is able to select another one. If any body can point me in the right direction I would be grateful. code is shown below.
Thanks in advance
Chazza
#include <SD.h>
#include <AudioZero.h>
#include <Arduino.h>
#include <FlashStorage.h>
const int station1 = 4; // the number of the pushbutton pin
const int station2 = 5; // the number of the pushbutton pin
void setup()
{
pinMode(station1, INPUT_PULLUP);
pinMode(station2, INPUT_PULLUP);
// debug output at 115200 baud
Serial.begin(115200);
// setup SD-card
Serial.print("Initializing SD card...");
if (!SD.begin(28)) {
Serial.println(" failed!");
while (true);
}
Serial.println(" done.");
// open wave file from sdcard
File myFile = SD.open("0.wav");
if (!myFile) {
// if the file didn't open, print an error and stop
Serial.println("error opening 0.wav");
while (true) {
}
}
Serial.println("Playing");
AudioZero.begin(2 * 44100);
// until the file is not finished
AudioZero.play(myFile);
Serial.println("End of file. Thank you for listening!");
} // end of setup ************************************
void loop()
{
if (digitalRead(station1 == LOW)) {
Serial.println("Station1");
playstation1();
}
if (digitalRead(station2 == LOW)) {
Serial.println("Station2");
playstation2();
}
}
void playstation1 () {
File myFile = SD.open("station1.wav");
AudioZero.play(myFile);
}
void playstation2 () {
File myFile = SD.open("station2.wav");
AudioZero.play(myFile);
}