Hoping for help from someone - have been trying various combinations of examples and etc. from WaveHC, along with my own code, to no avail. I am afraid I am missing some step…
Hardware I am using: a TinyDuino with audio and sd breakout.
What I want:
single file to play in a loop on power-up until it is interrupted.
file to stop playing on button press
loop to start again on next button press
What I have succeeded in getting:
single file to play in a loop on power-up until it is interrupted
file to stop playing on button press
file to play again on next button press, but only once
(and 2 & 3 repeat ad infinitum)
||
no file to play on power-up
file to play on button press
file to stop mid-play on button press
file to play again on button press
(and any combination of 2 & 4 or 2&3&4 ad infinitum)
Does anyone know how to get the file to resume playing on a loop after the loop is interrupted? I’ve attached what I’ve been working with.
Also: please do not recommend the WaveHC 6-button example from Adafruit. Been there, done that, doesn’t do what I want either.
you want to remove the "while" and go with a state change style code
example
//add to global
// byte prevbuttonstate=0;
// byte playRequest=0;
void loop() {
byte buttonstate = digitalRead(momSwitchPin);
if (prevbuttonstate != buttonstate) {// button has not changed state
if (buttonstate == 1) {// button changed state is is now high
if (!wave.isplaying) {//no wave playing request wave
playRequest == 1;//request wave flag
} else {//wave is playing so remove request
playRequest == 0;//remove wave flag request
}//close else
}//close buttonstate==1
}//close state change if
prevbuttonstate = buttonstate;//make equal so nothing will happen until
//button changes state
if (playRequest == 1) {//do you want to play wave
playfile("song1.wav");//start wave
} else {//you do not want to play so stop
wave.stop();//stop wave
}
}
You modified some code, some how. You failed to post it.
The code does something. You failed to say what.
You expected the modified code to do something. You failed to say what.
The great thing with state change code is that its print friendly. By adding serial prints you can follow the logic in blocks to see what the arduino is doing. Monitor button state and playrequest to see what the code is doing. This may be something as simple as the way the button is wired.
Read up about INPUT_PULLUP and decied if that's a better option for dealing with the button.
like pauls its doing something
you originally said
What I want:
single file to play in a loop on power-up until it is interrupted.
file to stop playing on button press
loop to start again on next button press
in the example I posted when you define byte playrequest as a global you would have to set it to default to 1 to make it play on start up. (or add the line playrequest=1; as the last line in setup)