Greetings,
I can not for the life of me figure out how to stop playing an mp3 using our push button. Please take a look at the following excerpt from my code. I excerpted the portion I need help with. The full code is too big to place here but has been attached.
//////////////////////////////////////////////////////////////////////////////////////////////
count = 0;
played = 0;
while(count<counter*10) //delay of some selected time delay with the checking of input
{
pressed = debounceRead(p_button);
delay(100);
if (pressed == LOW) //the button is pressed
{
if (! musicPlayer.startPlayingFile("MUSIC/track002.mp3")) {
Serial.println("Could not open file track001.mp3");
while (1);
}
Serial.println(F("Started playing"));
while (musicPlayer.playingMusic) {
// file is now playing in the 'background' so now's a good time
// to do something else like handling LEDs or buttons :)
Serial.print(".");
if (Serial.available()) {
char c = Serial.read();
// if we get an 's' on the serial console, stop!
pressed = debounceRead(p_button);
delay(100);
// if (c == 's') {
if (pressed==LOW) {
musicPlayer.stopPlaying();
}
delay(1000);
}
Serial.println("Done playing music");
}
}
count++;
}
pressed = HIGH;
}
/////////////////////////////////////////////////////////////////////////////////////////////
Using the serial console interface, it stops perfectly fine when I enter 's'.
When I try it using the button , it does not stop it.
Am I placing the
pressed = HIGH;
in the wrong location?
Casptone_Program_Loop_Works.ino (12.7 KB)