SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By AllenPitts
#178824
Hello SparkFun Forum,

OK last question.

The MP3 sketches in the Examples library (File Player
and MP3Shield_Library_Demo) both (I think) require
input via the Serial Monitor to get a track to play.
The application envisioned would use a signal
from a PIR Sensor to take a Pin 1 low to play
track001.mp3.

So I put together a sketch (code below) to
do that but I get
sketch_jan18a.ino: In function 'void loop()':
sketch_jan18a.ino:28:5: error: 'MP3player' was not declared in this scope

1. Not sure what "In function 'void loop()':" means?
2. The function MP3player is declared in the include
<SFEMP3Shield.h> so it seems like it is declared by reference.

Have looked for a simple MP3 shield player ino
but the two example files are several hundred lines
long so it is hard to boil them down t simplicity.

Thanks.

Allen in Dallas
Code: Select all
/**
 * \file MP3Shield_Play_From_Pin_Low.ino
 * This sketch plays a track when the digital pin is set to low.
 * For instance, when Pin O is grounded the MP3 Shield plays track001.mp3
 * Sketch assumes you have MP3 files with filenames like "track001.mp3",
 * "track002.mp3", etc on an SD card loaded into the shield.
 */
 
#include <SPI.h>
 
//Add the SdFat Libraries
#include <SdFat.h>
#include <SdFatUtil.h>
 
 //and the MP3 Shield Library
#include <SFEMP3Shield.h>
 
void setup() {
pinMode(0, INPUT);
pinMode(1, INPUT);

}

void loop() {
  // main code here, to run repeatedly:
  if (0 == LOW)  
   {
    MP3player.playTrack(1)
   }
}
 
By Mee_n_Mac
#178843
AllenPitts wrote:The application envisioned would use a signal
from a PIR Sensor to take a Pin 1 low to play track001.mp3.
And where in the code that you posted would that be ? This ...
Code: Select all
  if (0 == LOW) 
   {
    MP3player.playTrack(1)
   }
... doesn't do that. It (literally) asks if 0 is equivalent to a LOW, which it is. Perhaps you wanted to ask if pin(0) was a low ? If so ...
http://arduino.cc/en/Reference/DigitalRead
... you need to "read" the pin (first) to ascertain it's state, HIGH or LOW.
AllenPitts wrote:So I put together a sketch (code below) to
do that but I get
sketch_jan18a.ino: In function 'void loop()':
sketch_jan18a.ino:28:5: error: 'MP3player' was not declared in this scope

1. Not sure what "In function 'void loop()':" means?
2. The function MP3player is declared in the include
<SFEMP3Shield.h> so it seems like it is declared by reference.
Yes but you didn't "instantiate" an version first. Look at the example here ...
https://github.com/madsci1016/Sparkfun- ... Player.ino
In particular that code creates an "object" called MP3player via this line :
Code: Select all
SFEMP3Shield MP3player;
MP3player can then use all the functions/methods described by the code named "SFEMP3Shield", including the playTrack(x) function.

MP3player isn't a special name, it could have been XXYYZZ so long as the code had this line
Code: Select all
SFEMP3Shield XXYYZZ;
prior to ...
Code: Select all
XXYYZZ.playTrack(1)