Hi,
unfortuantely i require some help getting audio output working with random-track-number filename generation. I'm using TMRpcm library, within code im generating char variable buffer which outputs in filename as it it on sdcard (eg. 1.wav) and here's where trouble begins - function tmrpcm.play(buffer) won't recognize filename because it operates on filename embedded in quotation marks [eg. tmrpcm.play("1.wav") instead of tmrpcm.play(1.wav)].
TLDR: Need help embedding sprintf output filename in quotation marks.
It's probably quite easy to solve, thought after few hours i still can't get it to work. Any help would be much appreciated.
#include <SD.h> // need to include the SD library
#define SD_ChipSelectPin 4 //using digital pin 4 on arduino nano 328, can use other pins
#include <TMRpcm.h> // also need to include this library...
#include <SPI.h>
TMRpcm tmrpcm; // create an object for use in this sketch
unsigned long time = 0;
void setup(){
randomSeed(analogRead(0));
tmrpcm.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
//Complimentary Output or Dual Speakers:
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) { // see if the card is present and can be initialized:
Serial.println("SD fail");
return; // don't do anything more if not
}
else{
Serial.println("SD ok");
}
tmrpcm.volume(1);
}
void loop(){
char buffer[10];
int rand = random(1,5);
Serial.println(rand); //debug
sprintf(buffer,"%d.wav",rand);
Serial.println(buffer); //debug
tmrpcm.play(buffer);
Serial.println("-------------------------"); //debug
delay(5000);
}