audio loop/stop on button press

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:

  1. single file to play in a loop on power-up until it is interrupted.
  2. file to stop playing on button press
  3. loop to start again on next button press

What I have succeeded in getting:

  1. single file to play in a loop on power-up until it is interrupted
  2. file to stop playing on button press
  3. file to play again on next button press, but only once
    (and 2 & 3 repeat ad infinitum)

||

  1. no file to play on power-up
  2. file to play on button press
  3. file to stop mid-play on button press
  4. 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.

one_button.ino (6.37 KB)

one_button_edit.ino (6.68 KB)

root_play.ino (7.4 KB)

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
  }
}

state change isn't solving it either. any other thoughts ?

My cheap MP3 modules have a PAUSE command.

state change isn't solving it either.

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.

any other thoughts ?

I'll keep them to myself.

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:

  1. single file to play in a loop on power-up until it is interrupted.
  2. file to stop playing on button press
  3. 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)