Hi, I have a prop telephone project, and I am using a generic YX5300 board, Arduino Uno, LCD panel and Keyboard.
Using the excellent SerialMP3Player library, and everything is working perfectly. Have the code all working except for how to read the return messages from the module and parse out the "finished playing" Message. I want to block further code execution until the "phonecall.mp3" is complete.
I'm not a good enough programmer to figure out how to open and parse the return messages. Does anyone have any sample code to do this? Here is the console window when I run the example "BasicCommands" sketch, so I know it's possible:
Thanks @xfpd - I took the code you referenced and made a function to check if it's still playing - works perfectly now. I am reading the value 0x3d for complete and then checking the filename playing. I left in some commented out debug code to see what was happening. All input is welcome and this has been a fun project.
static uint8_t ansbuf[10] = {0}; // Buffer for the answers.
/********************************************************************************/
/*Function: StillPlaying */
/*Parameter:- uint8_t b. void. */
/*Return: false if the 4th byte is 0x3d (complete) and the filename in the 7th byte */
/* Code modified from original by cefaloide
/* Examples https://github.com/cefaloide/ArduinoSerialMP3Player
*/
bool StillPlaying(uint8_t TrackNumber)
{
uint8_t i = 0;
bool state = true;
//String mp3answer = "";
// Get only 10 Bytes
while (mp3.available() && (i < 10))
{
uint8_t b = mp3.read();
ansbuf[i] = b;
i++;
//mp3answer += sbyte2hex(b);
}
//Serial.println(mp3answer);
// if the answer format is correct and file playing is complete
if ((ansbuf[3] == 0x3D) && (ansbuf[6] == TrackNumber))
{
state = false;
}
return state;
}
/********************************************************************************/
/*Function: sbyte2hex. Returns a byte data in HEX format. */
/*Parameter:- uint8_t b. Byte to convert to HEX. */
/*Return: String */
String sbyte2hex(uint8_t b)
{
String shex;
shex = "0X";
if (b < 16) shex += "0";
shex += String(b, HEX);
shex += " ";
return shex;
}