Hi guys I am trying to add 2x micro switch’s to my Sparkfun Mp3 player, and max out the sound.
I already have a 4x3 keypad working to select the tracks. I didn’t receive any error messages from the code, but the sound is still very low and when I press the micro switch, the track it players is stuck in a very fast loop.
I am a novice at this, so you may need to dumb it down for me.
#include <Keypad.h>
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
SdFat sd;
SFEMP3Shield MP3player;
const uint8_t volume = 0; // MP3 Player volume 0=max, 255=lowest (off)
const uint16_t monoMode = 1; // Mono setting 0=off, 3=max
long randNumber;
int trackNumber = 2;
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {A0,A1,A2,A3};
byte colPins[COLS] = {A4,A5,3};
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int footpin = 10; // change 10 to pin your microswitch uses.
int footstep = 0;
void setup()
{
pinMode(footpin,INPUT_PULLUP);
sd.begin(SD_SEL, SPI_HALF_SPEED);
MP3player.begin();
}
void loop() {
char key = kpd.getKey();
if(key != NO_KEY)
{
switch (key)
{
case '1':
if(MP3player.isPlaying()) MP3player.stopTrack();
MP3player.playMP3("track001.mp3");
break;
case '2':
if(MP3player.isPlaying()) MP3player.stopTrack();
MP3player.playMP3("track002.mp3");
break;
case '3':
if(MP3player.isPlaying()) MP3player.stopTrack();
MP3player.playMP3("track003.mp3");
break;
case '4':
if(MP3player.isPlaying()) MP3player.stopTrack();
MP3player.playMP3("track004.mp3");
break;
case '5':
if(MP3player.isPlaying()) MP3player.stopTrack();
MP3player.playMP3("track005.mp3");
break;
case '6':
if(MP3player.isPlaying()) MP3player.stopTrack();
MP3player.playMP3("track001.mp3");
break;
case '7':
if(MP3player.isPlaying()) MP3player.stopTrack();
MP3player.playMP3("track006.mp3");
break;
case '8':
if(MP3player.isPlaying()) MP3player.stopTrack();
MP3player.playMP3("track007.mp3");
break;
case '9':
if(MP3player.isPlaying()) MP3player.stopTrack();
MP3player.playMP3("track008.mp3");
break;
case '*':
if(MP3player.isPlaying()) MP3player.stopTrack();
MP3player.playMP3("track001.mp3");
break;
case '0':
if(MP3player.isPlaying()) MP3player.stopTrack();
MP3player.playMP3("track001.mp3");
break;
case '#':
if(MP3player.isPlaying()) MP3player.stopTrack();
MP3player.playMP3("track001.mp3");
break;
}
}
footstep = digitalRead(footpin);
if(footstep = 1 ){
delay(100);
if(MP3player.isPlaying()) MP3player.stopTrack();
MP3player.playMP3("track001.mp3");
}
}
void initMP3Player()
{
uint8_t result = MP3player.begin(); // init the mp3 player shield
if(result != 0) // check result, see readme for error codes.
{
// Error checking can go here!
}
MP3player.setVolume(volume, volume);
MP3player.setMonoMode(monoMode);
}