Controlling "Music Maker" MP3 Shield

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mondeo
 
Posts: 7
Joined: Sat Dec 06, 2014 7:17 am

Controlling "Music Maker" MP3 Shield

Post by mondeo »

Hello,
I like to play tracks with only one button as follows: press button once: play track1, press button again: play track2, press again play track3 etc.
If track4 is playing and press button it should start again with play track1.
See the sketch (loop) below. If the button is pressed once unfortunately it plays all 4 Tracks in series and stops after playing track4.
Maybe anybody can help me to find a solution? Thank you and regards, Urs
*******************************************************************

Code: Select all

void loop() {

  val = digitalRead(eingang);
  if (val == HIGH) {
    currentState = 1;}
  else {currentState = 0;}
  if (currentState != previousState) {if (currentState == 1) {counter = counter + 1;}}
  previousState = currentState;

  switch (counter) {
    case 1:
      for (int i = 0; i = 1; i = i + 1) {
       musicPlayer.playFullFile("track001.mp3");
       break;}
    case 2:
      for (int i = 0; i = 1; i = i + 1)  {
        musicPlayer.playFullFile("track002.mp3");
        break;}
    case 3:
      for (int i = 0; i = 1; i = i + 1) {
        musicPlayer.playFullFile("track003.mp3");
        break;}
    case 4:
      for (int i = 0; i = 1; i = i + 1) {
        musicPlayer.playFullFile("track004.mp3");
        counter = 0;
        break;
      }
  } 
  delay(100);
}
Last edited by adafruit_support_rick on Sat Feb 06, 2016 10:56 am, edited 1 time in total.
Reason: please use Code tags when posting code (</> button)

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Controlling "Music Maker" MP3 Shield

Post by adafruit_support_rick »

You will execute the switch statement regardless of the state of the pin. It will execute each time through the loop.

User avatar
mondeo
 
Posts: 7
Joined: Sat Dec 06, 2014 7:17 am

Re: Controlling "Music Maker" MP3 Shield

Post by mondeo »

Thank you for your reply I found a solution for the a.m. Problem.
Now I have another Problem: with "Music Maker" it seems to be possible to play tracks in the background. Is it possible to check and save an input state during play a song? Example: I start track001 with push a button. Normally I have to wait until track001 is finish to push the button again. Now my idee is: to play track001 in background modus, so I can push the button again and memorize it during play track001. If track001 is played it could read the memory and play the next track.
It would be great if you can give me tipps or codes to solve this matter. Or maybe you can inform me what I have to search on Internet to find some usefull codes.
Thank you and best regards, Urs

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Controlling "Music Maker" MP3 Shield

Post by adafruit_support_rick »

Just call musicPlayer.startPlayingFile. It will return immediately and you can do whatever you want. Check musicPlayer.stopped to determine when the sound has finished playing.

User avatar
mondeo
 
Posts: 7
Joined: Sat Dec 06, 2014 7:17 am

Re: Controlling "Music Maker" MP3 Shield

Post by mondeo »

Thank you for your information. Please can you give me a short example which include the following codes, so I can imagine how to use the codes in programming:

musicPlayer.startPlaying File
musiPlayer.stopped
musicPlayer.playingMusic

Thank you very much for help
Urs

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Controlling "Music Maker" MP3 Shield

Post by adafruit_support_rick »

Just look at the simple_player example in the VS1053 library. It does all that.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”