...continued
Hitting any button in attract mode switches the state to INTRO. INTRO initializes the game state, plays an MP3 file that gives instructions to the user on how to run the machine, and waits for the user to hit a button. INTRO used to play the MP3 fine, until I hooked up all of the hardware, now it plays nothing, but the SFEMP3Shield object reports that the track played fine (0 return value from SFEMP3Shield::playMP3(char*)). The INTRO code is really simple:
#include <arduino.h>
#include "intro.h"
#include "kiosk.h"
void enter_INTRO(GameState& game)
{
static int track;
game.score = 0;
for(track = 0; track < NUM_TRACKS; ++track)
game.trackPlayed[track] = false;
game.tracksPlayed = 0;
#ifndef MP3_DISABLE
game.mp3.playMP3("intro.mp3");
#endif
}
States body_INTRO(int dt, GameState& game)
{
if(wasAnyButtonPressed()
#ifndef MP3_DISABLE
|| game.mp3.isPlaying()
#endif
)
{
return SELECT_TRACK;
}
return INTRO;
}
Once the button is hit, it goes into SELECT TRACK. It's supposed to light up all of the buttons in the first bank, play an audio track of a person saying "select a track", and then wait for the user to hit a button. Instead, it lights up the first column of buttons and then freezes in the middle of calling SFEMP3Shield::playMP3. It specifically freezes on a line in which the library calls attachInterrupt to wait for the MP3 shield to request more data to load off of the SD card.
I read a few posts about serial output and some interrupts possibly competing for resources and creating a potential race condition, so I removed all of the serial output, but that did nothing.
As you can see in some of the code, I have a precompiler directive to switch on and off actually doing anything with the MP3 shield. Disabling the MP3 code does nothing to get past the deadlock, it still freezes in the SELECT TRACK state. I don't know exactly where in the code it is freezing yet, as I was trying to debug this over the phone with my project partner. But the fact that it still freezes in the same general location withouth that call to attachInterrupt drives me up a wall.
I'm clueless at this point. We've rechecked all of the hardware and it works fine when controlled by other sketches. It seems like there is something in this code in particular that is making it freeze. I'm of half a mind to rewrite the code from the ground up, this time with just Switches in place of the function-pointer based FSM.