Go Down

Topic: Interrupt simple Audio player (Read 485 times) previous topic - next topic

Brendan1979

Maybe someone can help.

I have 2 files that i want to play using the simple audio player and due board.
Depending which pin i pull high as different clip is played. The problem that i have is that i cant seem to get the interrupt of one clip by another working.

I am trying to do it with a if loop and a break but it does not seem to work.


void loop()
{
  int count=0;

  // open wave file from sdcard
  File myFile = SD.open("test.wav");
  if (!myFile) {
    // if the file didn't open, print an error and stop
    Serial.println("error opening test.wav");
    while (true);
  }

  const int S=1024; // Number of samples to read in block
  short buffer;

  Serial.print("Playing");
  // until the file is not finished
  while (myFile.available()) {
    // read from the file into buffer
    myFile.read(buffer, sizeof(buffer));
 
   If (digitalRead (button1) ==HIGH)
    {
      break;
    }




    // Prepare samples
    int volume = 1023;
    Audio.prepare(buffer, S, volume);
    // Feed samples to audio
    Audio.write(buffer, S);

    // Every 100 block print a '.'
    count++;
    if (count == 100) {
      Serial.print(".");
      count = 0;
    }

Brendan1979

So what I am actually asking is how to stop 1 file and play another?

Go Up