SparkFun Forums 

Where electronics enthusiasts find answers.

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!
User avatar
By exeng
#192901
I've been enjoying using the WAV trigger to provide a voice for a project that I'm working on and building slowly. In doing so I have found that I was frequently playing bits of complete phrases separately and/or needing to wait for a solo track to finish before starting the next track. I ended up creating a couple of routines that may perhaps be useful to others.

The routines are wait4TackEnd(int trk); and playSoloWait4End(int trk, int gain);
NOTE: You will need to update your WAV Trigger to firmware 1.30b in order to make use of the WAV trigger reporting capability if you decide to use these.

What follows are some snippets of code (not complete) that show these routines and a possible usage example (mostly comments).

This code is a work in progress and may change but these routines have been proven to be useful in my application. Oh, and if there is a better way, please share.
Code: Select all
// In setup after start make sure you set reporting on
// Will require WAV Trigger firmware 1.30b 
 
...
  wTrig.start();
  delay(10);
  wTrig.setReporting(true);
...

// This routine simply waits for a track to end before returning
// to the caller.
void wait4TrackEnd(int trk) {
  int attn; // Ignore this. See note below.
  
  delay(1000); // Adjust as needed.
  while(wTrig.isTrackPlaying(trk) == true) {
    delay(1000); // Adjust as needed.
    wTrig.update();
// The ATTNCheck(); is used to check an for a button press
// interrupt to bail or do something useful in my code.
//    attn = ATTNCheck();
//    take some appropriate action if button pressed 
  }
}

// This routine plays a track solo and sets track gain.
// It then waits for the track to finish before returning.
void playSoloWait4End(int trk, int gain) {
      wTrig.trackGain(trk, gain);             
      wTrig.trackPlaySolo(trk);             
      // wait until track is finished
      wait4TrackEnd(trk);
}

...
// Usage (partial) example for a trivia game might be...
  int TQgain = -20;
  // TQ prefixed vars contain wav numbers
  playSoloWait4End(TQintro, TQgain); // Play an intro, e.g. "Let's get started"
  for (i=0; i<questions; i++) {
    playSoloWait4End(TQ[i].quest, TQgain); // Play the question wav
    playSoloWait4End(TQ_isit, TQgain);     // "Is it" wav
    playSoloWait4End(TQ_A,TQgain);         // "A" wav
    playSoloWait4End(TQ[i].ansA, TQgain);  // Answer A wav
    playSoloWait4End(TQ_B,TQgain);         // "B" wav
    playSoloWait4End(TQ[i].ansB, TQgain);  // Answer B wav
    playSoloWait4End(TQ_orC,TQgain);       // "or C" wav
    playSoloWait4End(TQ[i].ansC, TQgain);  // Answer C wav
// Psuedo code...
    // Wait for A, B, or C button press
    // Check against correct anwser
    // Respond accordingly
    // Update score
  }
...