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