hi guys,
i am making a arduino based music player which plays .wav files. unfortunately, the pause button does not work. i am sure that the circuit is well connected. what should be the problem with my codes? please help asap. thanks! btw, when the pause button is pressed, it shoul pause the current playing song, and when pressed again it should resume playing the song but it does not happen
#include “SD.h”
#include “TMRpcm.h”
#include “SPI.h”
#define SD_ChipSelectPin 4
TMRpcm music;
int song_number=0;
boolean debounce1=true;
boolean debounce2=true;
boolean play_pause;
void setup()
{
music.speakerPin = 9;
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin))
{
Serial.println(“SD fail”);
return;
}
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
music.setVolume(5);
music.quality(1);
}
void loop()
{
if (digitalRead(2)==LOW && debounce1 == true)
{
song_number++;
if (song_number==5)
{
song_number=1;
}
debounce1=false;
Serial.println(“KEY PRESSED”);
Serial.print(“song_number=”);
Serial.println(song_number);
if (song_number ==1)
{
music.play((char*)“1.wav”);
delay(300);
}
if (song_number ==2)
{
music.play((char*)“2.wav”);
delay(300);
}
if (song_number ==3)
{
music.play((char*)“3.wav”);
delay(300);
}
if (song_number ==4)
{
music.play((char*)“4.wav”);
delay(300);
}
if (digitalRead(3)==LOW && debounce2 == true)
{
music.pause();
Serial.println(“PLAY / PAUSE”);
debounce2=false;
}
if (digitalRead(2)==HIGH)
debounce1=true;
if (digitalRead(3)==HIGH)
debounce2=true;
}
}
musicplayer.ino (1.3 KB)