Skip to content

Instantly share code, notes, and snippets.

@Skwerl
Last active December 29, 2015 22:49
Show Gist options
  • Save Skwerl/7739278 to your computer and use it in GitHub Desktop.
Save Skwerl/7739278 to your computer and use it in GitHub Desktop.
Sparkfun MP3 Trigger via Serial TX2
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