Go Down

Topic: Vs1053 shield stops playing audio files (Read 665 times) previous topic - next topic

Samfag

Hi!
Im working on a project including a keypad, VS1053 mp3 audio shield, a button and an UNO.
The plan is to have different sounds playing when I input different codes on the keypad. The code below works perfect  until I stop one audio track on the button and input another code on the keypad to play another audio file. Sometimes it plays up the second audio track once but then it doesn't play. According to the serial monitor it should be playing. It doesnt matter if I try a diffrent audiotrack code not even the one I started with.
Is there some problems with my shield or is there some bug in my code?


Code: [Select]
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
#include <Bounce2.h>
#include <Keypad.h>


char password[5]; // number of characters in our password
int currentLength = 0; //defines which number we are currently writing
int i = 0;
int tries = 0;
char entered[5];

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'2', '2', '3', '1'},
  {'5', '6', 'B', '4'},
  {'7', '9', '8', '7'},
  {'*', '#', '0', '*'}
};
byte rowPins[ROWS] = {10, 5, 4, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A0, A1, A2, A3}; //connect to the column pinouts of the keypad


Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


#define B_STOP  A5

#define BUTTON_DEBOUNCE_PERIOD 20 //ms


SdFat sd;

SFEMP3Shield MP3player;

Bounce b_Stop  = Bounce();




void setup() {


  Serial.begin(115200);

  pinMode(B_STOP, INPUT_PULLUP);
 

  b_Stop.attach(B_STOP);
  b_Stop.interval(BUTTON_DEBOUNCE_PERIOD);
 

  if (!sd.begin(9, SPI_HALF_SPEED)) sd.initErrorHalt();
  if (!sd.chdir("/")) sd.errorHalt("sd.chdir");

  MP3player.begin();
  MP3player.setVolume(3, 3);

  Serial.println(F("Waiting for code attemt..."));

}

void loop()
{
  // Below is only needed if not interrupt driven. Safe to remove if not using.
#if defined(USE_MP3_REFILL_MEANS) \
    && ( (USE_MP3_REFILL_MEANS == USE_MP3_SimpleTimer) \
    ||   (USE_MP3_REFILL_MEANS == USE_MP3_Polled)      )

  MP3player.available();
  MP3player.setMonoMode(2);
#endif


  if (b_Stop.update()) {
    if (b_Stop.read() == LOW) {
      Serial.println(F("STOP pressed, Stopping Track"));
      MP3player.stopTrack();
      currentLength = 0;
    }
  }


  char key2 = keypad.getKey(); // get the key

  if (key2 == '0')
  {


    while (currentLength < 5)
    {
      char key2 = keypad.getKey();
      if (key2 == '#')
      {
        currentLength = 0;

      }
      else if (key2 != NO_KEY)
      {
        entered[currentLength] = key2;
        currentLength++;

      }
    }

    if (currentLength == 5)
    {
      if (entered[0] == '6' && entered[1] == '5' && entered[2] == '4' && entered[3] == '7' && entered[4] == '5' )

      {
        Serial.println("Song1");
        MP3player.playTrack(1);
       
       
      }
      else if (entered[0] == '6' && entered[1] == '5' && entered[2] == '4' && entered[3] == '7' && entered[4] == '4')

      {
        Serial.println("Song2");
        MP3player.playTrack(2);
       
      }

      else
      {
        Serial.println("SongFail");
        MP3player.playTrack(3);
       
        }
    }
  }
}

Samfag

Solved it by using the button to the reset pin on the Uno. Not the best way but now it works.

Go Up