Hi.
I am using the SimpeSDAudio library to play an audio sample when I press a button. But I want the audio to play continuously only while the button is pressed down.
I have managed to play the whole recording when you press the button once and also to continuously read the pushbutton data, but then it plays the recording from the beginning every time.
The current code below plays the sample until the end when you press the button once. How could I get it to continue reading the pushbutton data and while it reads '1' continuously play the audio and stop when it reads '0' again even if the recording hasn't finished?
#include <SimpleSDAudio.h>
const int buttonPin = 2;
int buttonState = 0;
void setup()
{
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}
void loop(void) {
buttonState = digitalRead(buttonPin);
Serial.println(buttonState);
if (buttonState == HIGH) {
if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO | SSDA_MODE_AUTOWORKER)) {
Serial.println(SdPlay.getLastError());
while(1);
}
if(!SdPlay.setFile("MaleNEW.raw")) {
Serial.println(SdPlay.getLastError());
while(1);
}
SdPlay.play();
// deleting this part keeps reading button data:
while(!SdPlay.isStopped()) {
;
}
SdPlay.deInit();
}
}[code]