Project: Playing Wav Audio Files in Sequence Using One Button

Hi,

I'm trying to build a sequential wav audio player using one button that will reset to the first wav file when completing all files played. I'm using TMRpcm library for this project.

I am novice, and have been trying to figure out the snag for a couple of weeks now. Pointers in the right direction or flat out "This is what you do" instructions are good too...I just feel like I hit a wall.

Any help appreciated.

#include <SPI.h>
#include <SD.h>                      // need to include the SD library
#define SD_ChipSelectPin 4  //using digital pin 4 on arduino nano 328
#include <TMRpcm.h>           //  also need to include this library...

TMRpcm tmrpcm;   // create an object for use in this sketch
 
int buttonPin = 2;  // button pin variable
int val = 0; // variable to read button pin value
int sequence = 1; // variable to hold current sequence
 
void setup(){
 
  tmrpcm.speakerPin = 9; //11 on Mega, 9 on Uno, Nano, etc
 
  if (!SD.begin(SD_ChipSelectPin)) {  // see if the card is present and can be initialized:
  return;   // don't do anything more if not
  }
 tmrpcm.volume(1);
 tmrpcm.play("start.wav"); //the sound file "1" will play each time the arduino powers up, or is reset
}
 
void loop()
{
//check if button pressed
val = digitalRead(buttonPin);
        if(val == LOW) 
        {
            if(sequence == 6) // if sequence is at 6, it'll loop back sequence 1
            {
               sequence = 1;
            } else
                {
                  sequence++; // otherwise go to the next sequence
                }
                delay(1); // delay of pushbutton
        }
                             
         switch(sequence)
                 {
                     case 1:
                     tmrpcm.play("01.wav");
                     break;
                     case 2:
                     tmrpcm.play("02.wav");
                     break;
                     case 3:
                     tmrpcm.play("03.wav");
                     break;
                     case 4:
                     tmrpcm.play("04.wav");
                     break;
                     case 5:
                     tmrpcm.play("05.wav");
                     break;
                     case 6:
                     tmrpcm.play("06.wav");
                     break;
                 }                         
}

sideswipe2674:
Any help appreciated.

I have had a look at your code. What is the problem that you need help with ?

What does your program do? and what do you want it to do differently ?

...R

Robin2:
I have had a look at your code. What is the problem that you need help with ?

What does your program do? and what do you want it to do differently ?

...R

Hi Robin,

Thanks for taking a look.

What My Program is Supposed To Do:

Powering up or resetting the arduino the file start.wav file should play

When pushing down the button (buttonpin = 2) 01.wav file should play
Upon pushing down the button again (buttonpin = 2) 02.wav file should play.
Upon pushing down the button again (buttonpin = 2) 03.wav file should play.
Upon pushing down the button again (buttonpin = 2) 04.wav file should play.
Upon pushing down the button again (buttonpin = 2) 05.wav file should play.
Upon pushing down the button again (buttonpin = 2) 06.wav file should play.

After the last wave file is played (06.wav) pushing down the button again (buttonpin = 2) 01.wav file should play, restarting the sequence.

What My Program is Doing:

Powering up or resetting the arduino the speaker plays a "buzz ping" sound.
A high humming sound can be heard on the speaker after the "buzz ping" sound.
When pushing down the button (buttonpin = 2) a low humming sound can be heard
Upon release of the button (buttonpin = 2) the high humming sound can be heard

sideswipe2674:
What My Program is Doing:

Your description of the symptoms does not seem to have anything to do with your title.

The basic problem seems to be that you cannot play a .wav file
And, sorry, but I don't know anything about that.

It might help to edit your original post and give it a more relevant title.

...R

Thanks for your input and taking the time to read. I modified the title to let visitors know it's a project about playing wav files.

sideswipe2674:
Thanks for your input and taking the time to read. I modified the title to let visitors know it's a project about playing wav files.

I have noticed the change. However your title still gives me the impression that the problem is with the button whereas, I think from your description, it is with the WAV files.

Have you been able to write a short program that plays one file correctly ? If so please post that code.
Have you tried that code with every one of your .wav files - in case there is a corrupt file.

Just a wild guess (if you can play the files) - if the code does not wait while a .wav file plays it may be trying to cycle through the files very quickly. For test purposes put a delay(500); as the last thing in loop() - to give you time to take your finger off the button

...R

Format your micro-sd card with FAT32 Option. Use Sample wave converter to convert your sound files and select the options as 16,000Hz Mono 8Bit.