Skip to content

Instantly share code, notes, and snippets.

@rahulbot
Last active March 7, 2024 19:51
Show Gist options
  • Save rahulbot/a624f70fd5973fb86bbb74273cdb6485 to your computer and use it in GitHub Desktop.
Save rahulbot/a624f70fd5973fb86bbb74273cdb6485 to your computer and use it in GitHub Desktop.
#include <DFRobot_DF1201S.h>
#include <SoftwareSerial.h>
// Tell Arduino which pins are wired to MP3 player (remember RX on Arduino is TX on MP3 player)
SoftwareSerial DF1201SSerial(2, 3); //Arduino RX, Arduino TX
// object that will handle all comms to MP3 player
DFRobot_DF1201S DF1201S;
void setup(void){
pinMode(13, OUTPUT);
// Initialize MP3 player communications
DF1201SSerial.begin(115200);
while(!DF1201S.begin(DF1201SSerial)){
Serial.println("Init failed, please check the wire connection!");
delay(1000);
}
DF1201S.setVol(4); // set a low-ish volume (valid values from 0 to 30)
delay(500);
DF1201S.switchFunction(DF1201S.MUSIC); // be a music player, not a USB drive
delay(500);
DF1201S.setPlayMode(DF1201S.SINGLE); // tell it to play just one file at a time (do this after switchFunction)
delay(500);
}
void loop(){
digitalWrite(13, LOW);
int result = DF1201S.playFileNum(1); // turn on LED if it play says it worked
if (result == 1) { // turn on Arduino LED if board says it worked
digitalWrite(13, HIGH);
}
delay(4000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment