There are 3 different notes, a high pitch, a middle pitch and a low pitch. Each note is for about 2 seconds and there is a 1s pause between the notes.
It’s from the Muppets, called Mah na Mah na.
It plays the songs with the extensions .wav or .mp3. It skips files with the extension .txt. It plays songs only in the main directory of the SD card.
//declare a variable called songVol
int songVol = 1023;
//check if mp3 volume is same as EEPROM volume
if(EEPROM.read(songVol) != mp3_vol){
//if not equal, write it
EEPROM.write(songVol, mp3_vol);
}else{
//if equal, then read it
Mp3.volume(EEPROM.read(songVol));
}
✔
Taken from lab 2. ✔
Pros - allows us to read different states like rising edge, falling edge and change.
Cons - It's not compatible with interrupts. Still using delay which slows down program.
volatile int isPlaying = HIGH;
void setup(){
attachInterrupt(1, playPause, LOW);
}
void playPause(){
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
if (interrupt_time - last_interrupt_time > 200) {
if(isPlaying ==HIGH){
isPlaying = LOW;
} else{
isPlaying= HIGH;
}
}
last_interrupt_time = interrupt_time;
}
void mp3_play (SdFile *file) {
do {
if(isPlaying==HIGH ){
bytes_to_read = file->read(bytes, read_buffer);
Mp3.play(bytes, bytes_to_read);
}
}
while (bytes_to_read == read_buffer);
}
✔