I'm trying to build an application that will use the TMRpcm library to play a variety of wav files.
The idea is that I will have an array of file names and, depending on a button selection, one of those file names will be passed to a routine that will play said file using TMRpcm.play.
The TMRpcm.play function expects a file name as follows:
TMRpcm.play("filename.wav")
I tried to set a String variable (playtone) that would include the filename and brackets and pass that to my routine, but that's not working.
I don't know if I'm trying to do something that's impossible, or simply experiencing some sort of brain cramp preventing me from seeing the obvious. Regardless, any help is appreciated.
Thanks.
Code follows:
#include <SD.h> // SD library
#define SD_ChipSelectPin 10 //pin connected to CS pin on SD card.
/* Other SD card pin connections:
* CS - 10
* SCK - 13
* MOSI - 11
* MOSO - 12
*/
#include <TMRpcm.h> // also need to include this library...
#include <SPI.h>
TMRpcm tmrpcm; // create an object for use in this sketch
int buttonInput = 0; // current analog value read from pin A0
int tuneSelection = 0; // which set of songs/tunes selected based on reading of pin A1
String playtone;
void setup(){
/Set the volume and check that the SD card is installed and operational.
tmrpcm.speakerPin = 9; // speaker output pin
Serial.begin(9600);
while (!SD.begin(SD_ChipSelectPin)) { // see if the card is present and can be initialized:
// If card not ready, flash red pin
Serial.println("SD fail");
delay (1000); // wait for a second
}
}
void loop(){
buttonInput = analogRead(A0); //Check if a button has been pressed
if (buttonInput >= 0 && buttonInput <= 200) {
String playtone = "Raffi1.wav";
playTune(playtone);
}
}
void playTune (String playtone){
tmrpcm.play(playtone);
while (tmrpcm.isPlaying()){
delay(500);
}
}