SparkFun Forums 

Where electronics enthusiasts find answers.

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!
By Gaviscon69
#197848
Hi guys!,

Very new to this world. And turns out I suck at it.

What I have tried to make:

A "Quest board". Simply put, a "board" which would have just a printed piece of paper on it, with buttons down the bottom.
When you press a button, the button lights up for a short duration, then turns off.
That same button will play a specific sound. A constant of sorts. That track will be bound to that button.

I tried to make the Quest board with 2 buttons, with the end goal being 3 buttons. However, I cannot seem to plagiarize enough examples to get it working. So I have come to the community of amazing people (you guys) to help me on my quest to make a quest board 8)

What I have:
  • 1x SparkFun Redboard
  • 1x SparkFun Breadboard
  • 1x SparkFun MP3 Shield (With soldered headers)
What works (so far):

So, I had a "simple" (even that was hard for me) code for lighting up a LED when I press a button.
When I press one button, it lit up and died after 500 milliseconds. When I press a different button, if lit up and died after 500 milliseconds.
Although one side seems to be clunky and takes a longer press.. (always activates half a second slower than the other light), It works. So it's acceptable to me.

I've also loaded up 3 tracks with the name of "Track001.mp3, Track002.mp3, Track003.mp3"
Using the example SFEMP3Shield "File Player" I found that these tracks are playing and working. (YAY!)
I found out the hard way I was blocking signals by putting my LEDs and Buttons anywhere on the board (whoops)

What does not work:

Simply put. Putting these two together.
I tried using the SFEMP3Shield "MP3ButtonPlayer2" but I found it was far too complex for what I needed. Not to mention the code in it was so confusing. Even with all the walk-throughs.

Current code listed below:
Code: Select all
#include <SPI.h>           // SPI library
#include <SdFat.h>         // SDFat Library
#include <SFEMP3Shield.h>  // Mp3 Shield Library

SdFat sd; // Create object to handle SD functions
SFEMP3Shield MP3player; // Create Mp3 library object

// some stereo options:
const uint8_t volume = 0; // MP3 Player volume 0=max, 255=lowest (off)
const uint16_t monoMode = 1;  // Mono setting 0=off, 3=max

// constants won't change. They're used here to set pin numbers:
const int buttonPin1 = A5;     // the number of the pushbutton pin
const int buttonPin2 = A0;     // the number of the pushbutton pin
const int ledPin1 =  5;      // the number of the LED pin
const int ledPin2 =  10;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  
  // initialize the LED pin as an output:
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);

MP3player.begin();
}

void loop() {
  // read the state of the pushbutton value:
  int buttonState1 = digitalRead(buttonPin1);
  int buttonState2 = digitalRead(buttonPin2);

  // check if the pushbutton1 is pressed. If it is, the buttonState is HIGH:
  if (((buttonState1 == LOW)
      && !
      ((buttonState1 == LOW) && (buttonState2 ==LOW))))
  {
    // turn LED on and play track 1:
    MP3player.playTrack(Track001.mp3)
    digitalWrite(ledPin1, HIGH);  // Turn the LED on
  } else {
    MP3player.stopTrack(Track001.mp3)
    delay(500);
    digitalWrite(ledPin1, LOW);    // turn LED off
  }
   if (((buttonState2 == LOW)
      && !
      ((buttonState1 == LOW) && (buttonState2 ==LOW))))
  {
    // turn LED on play track 2:
    MP3player.playTrack(Track002.mp3)
    digitalWrite(ledPin2, HIGH);  // Turn the LED on
  } else {
    delay(500);
    MP3player.stopTrack(Track002.mp3)
    digitalWrite(ledPin2, LOW);    // turn LED off
  }
}
As you might be able to see. I'm trying to play just a SINGLE track per button press. But they have to be specific to those buttons. So they can't rotate to a different song if I press the same button.
This is literally so I can have an "Accept".mp3, "Decline".mp3 and "CompleteQuest".mp3 which are labelled appropriately for the MP3Shield.
With only Accept (track001) and Decline (track002) being in the code so far.

Am I close? Or am I just copy pasting too much? I'm afraid I'm really struggling to understand what's going on at the best of times. So I'm just kind of trying to clutch at straws by reading examples and assuming if I put a piece of code in, under void loop or void setup, that it will act the same.

I'm also unsure how to call out the track numbers and use them in a call function.

The Error I'm currently getting:

Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\M_Servicedesk\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10805 -build-path C:\Users\M_SERV~1\AppData\Local\Temp\arduino_build_771125 -warnings=none -build-cache C:\Users\M_SERV~1\AppData\Local\Temp\arduino_cache_736592 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\M_Servicedesk\Documents\Arduino\Push_buttons\Push_buttons.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\M_Servicedesk\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10805 -build-path C:\Users\M_SERV~1\AppData\Local\Temp\arduino_build_771125 -warnings=none -build-cache C:\Users\M_SERV~1\AppData\Local\Temp\arduino_cache_736592 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\M_Servicedesk\Documents\Arduino\Push_buttons\Push_buttons.ino
Using board 'uno' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Detecting libraries used...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\M_SERV~1\AppData\Local\Temp\arduino_build_771125\sketch\Push_buttons.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "C:\Users\M_SERV~1\AppData\Local\Temp\arduino_build_771125\sketch\Push_buttons.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "C:\Users\M_SERV~1\AppData\Local\Temp\arduino_build_771125\sketch\Push_buttons.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Users\M_SERV~1\AppData\Local\Temp\arduino_build_771125\sketch\Push_buttons.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src\SPI.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\FatLib\FatFile.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\FatLib\FatFileLFN.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\FatLib\FatFilePrint.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\FatLib\FatFileSFN.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\FatLib\FatVolume.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\FatLib\FmtNumber.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\FatLib\StdioStream.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\FatLib\fstream.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\FatLib\istream.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\FatLib\ostream.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\MinimumSerial.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\SdCard\SdSpiCard.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\SdCard\SdSpiCardEX.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\SdCard\SdioCardEX.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\SdCard\SdioTeensy.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\SpiDriver\SdSpiESP8266.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\SpiDriver\SdSpiSAM3X.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\SpiDriver\SdSpiSTM32F1.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SdFat\src\SpiDriver\SdSpiTeensy3.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp" -o "nul"
Generating function prototypes...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Users\M_SERV~1\AppData\Local\Temp\arduino_build_771125\sketch\Push_buttons.ino.cpp" -o "C:\Users\M_SERV~1\AppData\Local\Temp\arduino_build_771125\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\M_SERV~1\AppData\Local\Temp\arduino_build_771125\preproc\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\SdFat\src" "-IC:\Program Files (x86)\Arduino\libraries\SFEMP3Shield" "C:\Users\M_SERV~1\AppData\Local\Temp\arduino_build_771125\sketch\Push_buttons.ino.cpp" -o "C:\Users\M_SERV~1\AppData\Local\Temp\arduino_build_771125\sketch\Push_buttons.ino.cpp.o"
C:\Users\M_Servicedesk\Documents\Arduino\Push_buttons\Push_buttons.ino: In function 'void loop()':

Push_buttons:70: error: 'Track001' was not declared in this scope

MP3player.playTrack(Track001.mp3)

^

Push_buttons:73: error: 'Track001' was not declared in this scope

MP3player.stopTrack(Track001.mp3)

^

Push_buttons:82: error: 'Track002' was not declared in this scope

MP3player.playTrack(Track002.mp3)

^

Push_buttons:86: error: 'Track002' was not declared in this scope

MP3player.stopTrack(Track002.mp3)

^

Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI
Using library SdFat at version 1.0.1 in folder: C:\Program Files (x86)\Arduino\libraries\SdFat
Using library SFEMP3Shield in folder: C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield (legacy)
exit status 1
'Track001' was not declared in this scope
By Gaviscon69
#197862
Ok so UPDATE I kept playing with this yesterday, while waiting for my post to be moderated.

So far this is my code:
Code: Select all
#include <SPI.h>           // SPI library
#include <SdFat.h>         // SDFat Library
#include <SFEMP3Shield.h>  // Mp3 Shield Library

SdFat sd; // Create object to handle SD functions
SFEMP3Shield MP3player; // Create Mp3 library object

// some stereo options:
const uint8_t volume = 0; // MP3 Player volume 0=max, 255=lowest (off)
const uint16_t monoMode = 1;  // Mono setting 0=off, 3=max

// constants won't change. They're used here to set pin numbers:
const int buttonPin1 = A5;     // the number of the pushbutton pin
const int buttonPin2 = A0;     // the number of the pushbutton pin
const int ledPin1 =  5;      // the number of the LED pin
const int ledPin2 =  10;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {

  // initialize the LED pin as an output:
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);

  //start the shield
  sd.begin(SD_SEL, SPI_FULL_SPEED);
  MP3player.begin();
}

void loop() {
  // read the state of the pushbutton value:
  int buttonState1 = digitalRead(buttonPin1);
  int buttonState2 = digitalRead(buttonPin2);

  // check if the pushbutton1 is pressed. If it is, the buttonState is HIGH:
  if (((buttonState1 == LOW)
      && !
      ((buttonState1 == LOW) && (buttonState2 ==LOW))))
  {
    // turn LED on, and play track 1:
    MP3player.playTrack("Track001.mp3");
    digitalWrite(ledPin1, HIGH);  // Turn the LED on
  } else {
    delay(500);
    digitalWrite(ledPin1, LOW);    // turn LED off
  }
   if (((buttonState2 == LOW)
      && !
      ((buttonState1 == LOW) && (buttonState2 ==LOW))))
  {
    // turn LED on, and play track 2:
    MP3player.playTrack("Track002.mp3");
    digitalWrite(ledPin2, HIGH);  // Turn the LED on
  } else {
    delay(500);
    digitalWrite(ledPin2, LOW);    // turn LED off
  }
}
I've managed to upload it with no apparent errors. However...

The music won't play on button press!! :cry: Nooooooooooooooo!!
Can anybody see why the track won't play when I press a button!?!
By paulvha
#197864
are you sure your button pressed is being detected ? include a Serial.println(F("button x pressed")); for debug and to check...The other thing I am a bit worried about it the speed at which the loop() works. include a way to detect that it was released and pressed ..
Thoughts on sample code that is more modular (broken down in smaller parts to make it easier to understand, debug and maintain)... but NOT tested as I do not have a that shield.
Code: Select all
#include <SPI.h>           // SPI library
#include <SdFat.h>         // SDFat Library
#include <SFEMP3Shield.h>  // Mp3 Shield Library

SdFat sd;                  // Create object to handle SD functions
SFEMP3Shield MP3player;    // Create Mp3 library object

// some stereo options:
const uint8_t volume = 0;  // MP3 Player volume 0=max, 255=lowest (off)
const uint16_t monoMode = 1;  // Mono setting 0=off, 3=max

// constants won't change. They're used here to set pin numbers:
// actually try to avoid using the analog pin
const int buttonPin1 = A5;   // the number of the pushbutton pin
const int buttonPin2 = A0;   // the number of the pushbutton pin
const int ledPin1 =  5;      // the number of the LED pin
const int ledPin2 =  10;     // the number of the LED pin

// set led pins in structure
const int out_pin[2] = {
    lenPin1,
    ledPin2,
};

void setup() {
  
  int result;
  
  // initialize the LED pin as an output:
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  
  // initialize the pushbutton pin as an input:
  // make sure the button connected to ground when pressed
  pinMode(buttonPin1, INPUT_PULLUP );
  pinMode(buttonPin2, INPUT_PULLUP );

  //Initialize the SdCard.
  if(!sd.begin(SD_SEL, SPI_FULL_SPEED)) sd.initErrorHalt();
  // depending upon your SdCard environment, SPI_HAVE_SPEED may work better.
  if(!sd.chdir("/")) sd.errorHalt("sd.chdir");

  result = MP3player.begin();
  //check result, see readme for error codes.
  if(result != 0) {
    Serial.print(F("Error code: "));
    Serial.print(result);
    Serial.println(F(" when trying to start MP3 player"));
    if (result == 6) {
       Serial.println(F("Warning: patch file not found, skipping.")); // can be removed for space, if needed.
       Serial.println(F("Use the \"d\" command to verify SdCard can be read")); // can be removed for space, if needed.
    }
  }
  
}

void loop() 
{
  // indicate the previous state 1 = HIGH. 0 = LOW
  static int prev_status[2] = {1,1};
  
  // read the state of the pushbutton value:
  int buttonState1 = digitalRead(buttonPin1);
  int buttonState2 = digitalRead(buttonPin2);

  // check if the pushbutton1 is pressed. If it is, the buttonState is LOW:
  if (buttonState1 == LOW && buttonState2 == HIGH)
  {
    // if button1 was HIGH before 
    if (prev_status[0] == 1)
    {
        button_pressed(0);
        pre_status[0] = 0;
        pre_status[1] = 1;
    }
  } 
  
  else if (buttonState1 == HIGH && buttonState2 == LOW)
  {
    // if button2 was high before 
    if (prev_status[1] == 1)
    {
        button_pressed(1);
        pre_status[0] = 1;
        pre_status[1] = 0;
    }
  }
  
  else if (buttonState1 == LOW && buttonState2 == LOW)
  {
    // if BOTH were high  before 
    if (prev_status[0] == 1 && prev_status[1] == 1)
    {
        button_pressed(2);
        pre_status[0] = 0;
        pre_status[1] = 0;
    }
  }
  
  else 
  {
     // indicate that both are HIGH (released)
     pre_status[0] = 1;
     pre_status[1] = 1;
  }
    
}

// handles button pressed
void button_pressed(int index)
{
   int i;
   
   // indicate status (1 = playing, 0 = NOT playing)
   static button_stat[3] = {0};

   // stop playing current track
   MP3player.stopTrack();   
  
   // if track of current was playing. Stop it... Silence !!!
   if (button_stat[index] ==  1)
   {
        // stop led
        stop_led(index);
        
        // indicate NOT playing
        button_stat[index] = 0;

        return;
    }

   // different track is requested / reset first
   for (i = 0; i < 3; i++)
   {
        // stop led
        stop_led(i);
        
        // indicate NOT playing
        button_stat[i] = 0;
    }    

    // play track:
    start_track(index);
    
    // turn LED on
    start_led(index);

    // indicate playing
    button_stat[index] = 1;
}

// start track playing
void start_track(int index)
{
    if (index == 0) MP3player.playTrack("track001.mp3");
    else if (index == 1) MP3player.playTrack("track002.mp3");
    else MP3player.playTrack("track003.mp3");
}

// stop LED
void stop_led(int index);
{
    if (index == 2)
    {
        digitalWrite(out_pin[0], LOW);
        digitalWrite(out_pin[1], LOW);
    }
    else
    {
        digitalWrite(out_pin[index], LOW);
    }

}

// start LED
void start_led(int index)
{
    if (index == 2)
    {
        digitalWrite(out_pin[0], HIGH);
        digitalWrite(out_pin[1], HIGH);
    }
    else
    {
        digitalWrite(out_pin[index], HIGH);
    }
    
    // if ONLY a flash is wanted remove comments for the next 2 lines
    // delay(1000);     // flash 1 second
    // stop_led(index);
}
By Gaviscon69
#197868
Hi Paul!
Thanks for your reply! :D

So I've managed to get the music playing on button press. Of all things, the command: MP3player.playTrack("Track001.mp3") doesn't recognise the track.
I looked around and most people using this board actually had the command: MP3player.playTrack(1)

So the music now works! :D I knew the button was working because the LEDs were lighting up correctly on button press.
My issue now, is the reaction the board takes to actually play the tracks, upon button press.

My A0 Button / D10 LED take a long time (responds between 3 - 5 seconds) to recognise that the button has been pressed.
Whereas my A5 Button / D5 LED takes about between 1.5 - 3 seconds to recognise that the button has been pressed.

Is this what you're worried about? How fast the loop works?

I tried your code and it came up with error: 'pre_status' was not declared in this scope

Which originates from code:
Code: Select all
  else 
  {
     // indicate that both are HIGH (released)
     pre_status[0] = 1;
     pre_status[1] = 1;
This is my current code which plays the music upon button press, as well as lights up it's corresponding LED.
Only issue is, the timing. I want someone to be able to press it, and the board responds immediately, as best case scenario:
Code: Select all
#include <SPI.h>           // SPI library
#include <SdFat.h>         // SDFat Library
#include <SFEMP3Shield.h>  // Mp3 Shield Library

SdFat sd; // Create object to handle SD functions
SFEMP3Shield MP3player; // Create Mp3 library object

// some stereo options:
const uint8_t volume = 0; // MP3 Player volume 0=max, 255=lowest (off)
const uint16_t monoMode = 1;  // Mono setting 0=off, 3=max

// constants won't change. They're used here to set pin numbers:
const int buttonPin1 = A5;     // the number of the pushbutton pin
const int buttonPin2 = A0;     // the number of the pushbutton pin
const int ledPin1 =  5;      // the number of the LED pin
const int ledPin2 =  10;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {

  Serial.begin(9600);

  // initialize the LED pin as an output:
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);

  //start the shield
  sd.begin(SD_SEL, SPI_FULL_SPEED);
  MP3player.begin();
}

void loop() {
  // read the state of the pushbutton value:
  int buttonState1 = digitalRead(buttonPin1);
  int buttonState2 = digitalRead(buttonPin2);

  // check if the pushbutton1 is pressed. If it is, the buttonState is HIGH:
  if (((buttonState1 == LOW)
      && !
      ((buttonState1 == LOW) && (buttonState2 ==LOW))))
  {
    // turn LED on, and play track 1:
    MP3player.playTrack(1);
    Serial.println("Accepted the Quest");
    digitalWrite(ledPin1, HIGH);  // Turn the LED on
    delay(500);
  } else {
    delay(2000);
    digitalWrite(ledPin1, LOW);    // turn LED off
  }
   if (((buttonState2 == LOW)
      && !
      ((buttonState1 == LOW) && (buttonState2 ==LOW))))
  {
    // turn LED on, and play track 2:
    MP3player.playTrack(2);
    Serial.println("Declined the quest :sadface:");
    digitalWrite(ledPin2, HIGH);  // Turn the LED on
    delay(500);
  } else {
    delay(2000);
    digitalWrite(ledPin2, LOW);    // turn LED off
  }
}
Do you think the code is a bit stuttery? Is that why it's responding so slowly?
By paulvha
#197871
Good job that is works !. My code had not been tested nor compiled. I am sure there were more issues still to be fixed.

My concern was related that when your press the button to long it might be read again within the same press and turn the led off. Hence I included a loop that would detect that the button was released and only trigger an action when pressed again.

The other point is that you actually need a pull-up resistor so that the input is NOT floating when the button is NOT pressed. Hence I set the pinmode with
pinMode(buttonPin1, INPUT_PULLUP );

Last point, you could consider switch the input and output pins. So the A0 and A5 for the leds and 5 and 10 for input. The button is digital (one or zero), the leds could be driven analog : anologWrite(pin, value). with the value you can then also determine the brightness of the LED

regards,
Paul
User avatar
By DanV
#197874
Your code has a 500 millisecond delay if you are detecting a button press and turn on the LED and play the track.
If you are not detecting a button press, then you are having a 2000 millisecond delay - every pass through the loop - for each button.
the delay() function is a blocking function - the program stops right there until the function completes.
Google "blink without delay" and you can get to many examples / explanations of how to program without using blocking functions.
By Gaviscon69
#197880
paulvha wrote: Sat Jan 13, 2018 2:37 am My concern was related that when your press the button to long it might be read again within the same press and turn the led off. Hence I included a loop that would detect that the button was released and only trigger an action when pressed again.
Yes, so for some reason my D10 (Button) A0 (LED) actually does this. Because it takes so long to recognise the button has been pressed, it actually plays the sound twice. Which is annoying. I only want it to play once per button press.
I'm going to have a look at the code you gave me and try get it working. I'll see how well I can get it done. If I struggle too much I'll come back in a few days and ask you for a few pointers on how to get your button press loop code working.

The last error I got was:
exit status 1
'button_stat' does not name a type

paulvha wrote: Sat Jan 13, 2018 2:37 am The other point is that you actually need a pull-up resistor so that the input is NOT floating when the button is NOT pressed. Hence I set the pinmode with
pinMode(buttonPin1, INPUT_PULLUP );

Last point, you could consider switch the input and output pins. So the A0 and A5 for the leds and 5 and 10 for input. The button is digital (one or zero), the leds could be driven analog : anologWrite(pin, value). with the value you can then also determine the brightness of the LED
That's actually a really good idea. I didn't even take any notice that LEDs were Analogue! Maybe now I could find a bit of code that can make it look like the LED is turning off slowly, without one of those movement thingies (potentiometer?) And make it turn off slowly by issuing commands to reduce brightness to 0 over 3 seconds, within 200ms intervals or something.

I actually had resistors on my buttons but didn't know the command had to be INPUT_PULLUP
I changed the code to that now, but it's still acting the same. (Which I suppose isn't a bad thing)
By paulvha
#197887
on the delay, DanV has explained it.
press butttonpin1 : music starts, pin1 high, delay 500ms.
release buttonpin1 or No buttonpressed:button 1 is not pressed : delay 2000ms, then dimled1, as button2 is not pressed either : delay 2000Ms then dim led2. total 4 seconds delay
press buttonpin2: button 1 is not pressed : delay 2000ms, then dimled1,NOW (2 seconds later) it detects button2 was pressed: music starts, pin2 high, delay 500ms.
This can be avoided to define at the top in loop()
int prev_stat1 = HIGH, prev_stat2 = HIGH;

in the code (only showing for button1, similar to be included button2 )
Code: Select all
{
    // turn LED on, and play track 1:
    MP3player.playTrack(1);
    Serial.println("Accepted the Quest");
    digitalWrite(ledPin1, HIGH);  // Turn the LED on
    delay(500);
    prev_stat1 = LOW;
  } 
  else if (prev_stat1 == LOW) 
  {
    delay(2000);
    digitalWrite(ledPin1, LOW);    // turn LED off
    prev_stat1 = HIGH;
  }