Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Adafruit Wave Shield - Stopping Playback
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit Wave Shield - Stopping Playback

by AdamTheAwesome on Sun May 31, 2020 6:00 pm

Hello everybody, I am using the adafruit wave shield kit for arduino to build an alarm clock. My code is based off of one of the examples included with the Wave HC library (in this case it was daphc) I have been able to play audio from a SD card, but I have not been able to stop the audio playback. Here is the play function (from one of the adafruit examples) that is called at a certain time:
Code: Select all | TOGGLE FULL SIZE
  /*
     play recursively - possible stack overflow if subdirectories too nested
  */
  void play(FatReader & dir) {
    FatReader file;
    while (dir.readDir(dirBuf) > 0) {    // Read every file in the directory one at a time

      // Skip it if not a subdirectory and not a .WAV file
      if (!DIR_IS_SUBDIR(dirBuf)
          && strncmp_P((char *)&dirBuf.name[8], PSTR("WAV"), 3)) {
        continue;
      }

      Serial.println();            // clear out a new line

      for (uint8_t i = 0; i < dirLevel; i++) {
        Serial.write(' ');       // this is for prettyprinting, put spaces in front
      }
      if (!file.open(vol, dirBuf)) {        // open the file in the directory
        error("file.open failed");          // something went wrong
      }

      if (file.isDir()) {                   // check if we opened a new directory
        putstring("Subdir: ");
        printEntryName(dirBuf);
        Serial.println();
        dirLevel += 2;                      // add more spaces
        // play files in subdirectory
        play(file);                         // recursive!
        dirLevel -= 2;
      }
      else {
        // Aha! we found a file that isnt a directory
        putstring("Playing ");
        printEntryName(dirBuf);              // print it out
        if (!wave.create(file)) {            // Figure out, is it a WAV proper?
          putstring(" Not a valid WAV");     // ok skip it
        } else {
          Serial.println();                  // Hooray it IS a WAV proper!
          wave.play();                       // make some noise!

          uint8_t n = 0;
          while (wave.isplaying) {// playing occurs in interrupts, so we print dots in realtime
            putstring(".");
            if (!(++n % 32))Serial.println();
            delay(100);
          }
          sdErrorCheck();                    // everything OK?
          // if (wave.errors)Serial.println(wave.errors);     // wave decoding errors

        }
      }
    }
  }


This plays it recursively, but is only triggered at a certain time so it only plays once. However, when put in the void() loop it waits until it has completed playing the full audio file until continuing through the void loop (or this is what I assume is happening, if i'm wrong let me know). I have attached a button and used this code:
Code: Select all | TOGGLE FULL SIZE
    if (buttonState == HIGH) {
    // stop audio playback
    wave.stop();
    Serial.println("Snooze Activated");
  } else {
    //do nothing
  }

But this does not work because it waits for the audio to be played before going over these lines, meaning it doesn't do anything. If anybody knows how I could modify any part of this to fit my needs, answers are welcome. Also feel free to let me know if more information is needed, Thanks

AdamTheAwesome
 
Posts: 2
Joined: Mon Apr 13, 2020 9:18 pm

Re: Adafruit Wave Shield - Stopping Playback

by AdamTheAwesome on Sun Jun 07, 2020 2:27 pm

I need to complete this by June 16th as a gift for one of my friends, so if anyone knows how to fix my issue it would be greatly appreciated.

AdamTheAwesome
 
Posts: 2
Joined: Mon Apr 13, 2020 9:18 pm

Please be positive and constructive with your questions and comments.