The method sprintf() is not valid on Arduino. How else can I convert a string to char*?
if(triggerNumber == 4)
{ currenttrack = 5;
}
sprintf(trackName, "track%03d.mp3", currenttrack);
playMP3(trackName); //Go play XX.mp3
The method sprintf() is not valid on Arduino. How else can I convert a string to char*?
if(triggerNumber == 4)
{ currenttrack = 5;
}
sprintf(trackName, "track%03d.mp3", currenttrack);
playMP3(trackName); //Go play XX.mp3
I believe snprintf will work if you include stdio.h
snprintf(trackName, sizeof(trackName), "track%03d.mp3", currenttrack);
There is a String class in Arduino that you can use. In your case
String trackName = "track";
track += currentTrack;
if (currentTrack < 9) {
track += currentTrack;
}
else {
track += "0";
track += currentTrack;
}
track += ".mp3";
playMP3(trackName);
There are other String manipulation methods in the String class that may be useful. See http://arduino.cc/en/Reference/StringObject
you can simply use .c_str().
Returns a pointer to an array that contains a null-terminated sequence of characters (i.e., a C-string) representing the current value of the string object.