To get the MP3 Trigger to play, stop, and restart as intended, I had to set up a pair of ‘latches’ to (A) have it play then stop, and (B) reset when out of the tuning window. The first latch (isPlaying) is set when the track is started. The second latch (stopLatch) is set when the track is manually stopped, by moving out of the tuning window. isPlaying is reset to false when the track end signal is received (the MP3 trigger transmits an ‘X’ when the track ends or ‘x’ when playing is cancelled by action (MP3 trigger receives ‘O’).
see code samples below.
- C octal number declaration ‘feature’
– as they say, "it’s not a bug, it’s an undocumented feature" — note this is documented in the Arduino reference.
In C, a leading 0 (zero) declares a number as an octal, and Arduino is a descendant of C, via Java, and has therefore preserved this convention. So, when I tried sending track numbers such as Track 008, I started getting a strange error about octal constants. What octal constants? I’m not declaring anything as an octal … and why is it playing the wrong track? — because it’s considering it octally (base 8, 0..7) as opposed to decimally (0..9).
A workaround will have to be figured out, and I’m sure it won’t be particularly difficult, but this was an unpleasant surprise.
Hardware issues, and words of the wise:
Wiring everything together ‘elegantly’ often ends up with a problem. I thought I was being so slick soldering the grounds for the LED band indicators together. Of course one of them burned out. And now it’s a problem to replace it. Mercifully I can just clip it out and run a separate ground for that one, but it’s a good lesson: design for disassembly, especially with prototypes. "If something can go wrong, it will"- human factors researcher Edward A. Murphy (bet you didn’t know he was in the HF field, working with Stapp on the famous Rocket Sled!)
void playTrack(int track)
if (isPlaying == false) // check to see if a track is playing (would be true if playing)
isPlaying = true; // set isPlaying interlock
stopLatch = false; // open StopLatch interlock
Serial1.print(‘t’, BYTE); // track signal
if (isPlaying == true && stopLatch == false)
do // do-while loop tests condition at the end.
Serial1.print(‘O’, BYTE); // send play/stop signal to the MP3 trigger (in this case, stop signal)
stopLatch = true; // set interlock
while (Serial1.available() > 0); // check state of serial buffer
if (stopLatch = true)
Serial.println("stopLatch"); // print latch state to debugger
inByte = Serial1.read(); //Serial1 for Arduino Mega
if (inByte == ‘X’ or inByte == ‘x’)
isPlaying = false;// sets isPlaying latch open
Serial.print("ACK "); // for debugging purposes
digitalWrite(playLight, LOW); // debugging light
delay(20); // wait state 20ms for recycle