I can't see my error here. This code is pretty long but what I'm concerned with it the state machine TorpSequence. When it reaches case FLASHON, the file never triggers to play. I know its wired correctly because it will play with the example code it came with. (Again, I am not a programmer but please can someone show me what I did wrong here? Code might not post, 9k limit)
Yeah I couldn't post the code but the .ino is attached. I'm concerned with State Machine Torp Sequence. The RX and TX pins are defined but...I'm doing something wrong in this code.
FINAL_V3.0.ino (12.2 KB)
You're using a depricated library for the DFPlayer, you should use this one instead (installable via the Arduino IDE's Libraries Manager).
Other than that, I do see "case TORPSEQUENCE" doesn't have any way to escape and change state. I imagine that's another source of error in the code.
I will update my library. I tried moving the play command down to button states for button one after I posted but it failed to play.
Please post your new code in tags
I can't, it exceeds the 9k limit
Ok, then post your new code as an attachment. A wiring diagram would also be useful.
At this point it doesn't matter, I managed to get it to work but I'm disappointed I used delays. I inserted it into ENDSTATE of the stateMachineTorp(). Of course using delay pauses things so its not ideal but I need to define something like Mp3Millis or something. I'm just elated it works to a degree.
case ENDSTATE:
{
//wait here for 1 seconds
if (currentMillis - fadeMillis >= 100ul)
{
analogWrite(led1, 0);
myMP3.play(1);
delay (1000);
myMP3.sleep();
//we are now finished with this animation
mState1 = TORPSEQUENCE;
}
}
break;
Redefined code working
case ENDSTATE:
{
//wait here for 1 seconds
if (currentMillis - fadeMillis >= 100ul)
{
analogWrite(led1, 0);
myMP3.play(1);
if (currentMillis >= mp3Millis + period1) {
mp3Millis = currentMillis;
}
//we ar now finished with this animation
mState1 = TORPSEQUENCE;
}
}
break;