Hi yonghui,
Below are my codes. Im using the shield with a mega board.
- CODE: SELECT_ALL_CODE
#include <MP3Player.h>
MP3Player playerone(3, 2);
int button1 = 0;
int button2 = 0;
int state;
byte mute=0;
byte play_pause=1;
long debouncing_time = 15; //Debouncing Time in Milliseconds
volatile unsigned long last_micros;
void setup()
{
//initialize the player: setup STA013 from STA013.cfg file in SD card, print status to through serial terminal
playerone.Init();
playerone.Volume(240);
pinMode(6, INPUT);
pinMode(7, INPUT);
attachInterrupt(0, debounceInterrupt, RISING);
state = 0;
}
void loop()
{
button1 = digitalRead(7);
delay(10);
button2 = digitalRead(6);
delay(10);
if(state == 0)
{
play_nature();
}
else if(state == 1)
{
play_train();
}
}
void play_nature()
{
playerone.Init();
playerone.Volume(245);
playerone.Play("nature.mp3");
}
void play_train()
{
playerone.Init();
playerone.Volume(240);
playerone.Play("train.mp3");
state = 0;
}
void play_next()
{
change();
playerone.PLAY=false;
}
void change()
{
state = 1;
}
void debounceInterrupt() {
if((long)(micros() - last_micros) >= debouncing_time * 1000) {
Interrupt();
last_micros = micros();
}
}
void Interrupt() {
change();
playerone.PLAY=false;
}
As for schematic, it is not that complicated as i only used 1 button to pin 2 to trigger the interrupt and with that setup i also include the pulldown resistor to flush the line.
Together with this shield, i am also having some "clicking" sound whenever it changed the mp3 track but not as visible when i press the interrupt button. (i have created another thread for that issue.)
Best Regards
Cookietiau