Last active
December 29, 2015 22:49
-
-
Save Skwerl/7739278 to your computer and use it in GitHub Desktop.
Sparkfun MP3 Trigger via Serial TX2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int mp3Byte = 0; | |
boolean mp3Playing = false; | |
void setup() { | |
Serial2.begin(38400); | |
} | |
void loop() { | |
if (Serial2.available()) { | |
mp3Byte = Serial2.read(); | |
if (mp3Byte == 88) { // Sound finished playing | |
mp3Playing = false; | |
} | |
} | |
} | |
void playSound(int sample) { | |
if (mp3Playing == false) { | |
Serial2.write('t'); | |
Serial2.write(sample); | |
mp3Playing = true; | |
} | |
} | |
void stopSound() { | |
if (mp3Playing == true) { | |
Serial2.write('O'); | |
mp3Playing = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment