Malaysia
Offline
Newbie
Karma: 0
Posts: 19
Nobbie,first time
|
 |
« on: November 14, 2012, 08:29:43 am » |
Hey guys,i am a FNG in the world of arduino and i despreatly need help. My project is about the PIR sensor detecting motion and sending it to the Arduino Uno which will trigger the MP3 Shield,i have the code from online but how do u add the libraries to the sketch? */
// libraries
#include <SPI.h> #include <SdFat.h> #include <SdFatUtil.h> #include <SFEMP3Shield.h> SFEMP3Shield MP3player;
// constant variables int pirPin = 5; // PIR sensor input pin int calibrationTime = 10; unsigned long playTime = 15000; // how long a file will play in milliseconds (15000=15 seconds) unsigned long pauseTime = 10000; // how long the pause will be after the sound ends (10000=10 seconds) int readingInterval = 20; // how often to read the sensor // changing variables
int rantrack = 0; // track number for randomizing unsigned long currentMillis = 0; // time variable to track running time: current time unsigned long startingMillis = 0; // time variable to track running time: starting time byte result; // variable for mp3 player shield, can be used to debug // setup void setup() { pinMode(pirPin, INPUT); digitalWrite(pirPin, LOW);
//give the sensor some time to calibrate for(int i = 0; i < calibrationTime; i++){ delay(1000); } delay(50);
pinMode(pirPin, INPUT); // make PIR sensor an input digitalWrite(pirPin, LOW); // activate internal pull-up resistor result = MP3player.begin(); // start mp3 player shield MP3player.SetVolume(10, 10); // set volume of the mp3 player ( 0 = loudest ) } // loop void loop(){ if (digitalRead(pirPin)== HIGH) { // if movement sensed randomSeed(millis()); // set a more random seed for the random function rantrack = random(55); // find random number result = MP3player.playTrack(rantrack); // play track playtime(); // call function for play time MP3player.stopTrack(); // stop track delay(pauseTime); // wait... } delay(readingInterval); // wait with reading }
// function to determine playtime
void playtime() { startingMillis = millis(); // set both time counter currentMillis = millis(); while ( currentMillis - startingMillis < playTime ) { // while track plays, runs until playTime is reached currentMillis = millis(); // set to actual time delay(40); // debounce } }
the help i need is in this:
#include <SdFat.h> #include <SdFatUtil.h> #include <SFEMP3Shield.h> SFEMP3Shield MP3player; how do i add these??Please URGENTLY reply!! Thank You
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 313
Posts: 35507
Seattle, WA USA
|
 |
« Reply #1 on: November 14, 2012, 09:15:07 am » |
i have the code from online but how do u add the libraries to the sketch? Use #include statements to add the header files. If the header file defines a class, you need to create one (or more) instance(s) of the class. the help i need is in this:
#include <SdFat.h> #include <SdFatUtil.h> #include <SFEMP3Shield.h> SFEMP3Shield MP3player; how do i add these?? Just like in your sketch. Please URGENTLY reply!! When is our homework due? Why did we wait until the last minute? What is the problem we are trying to address?
|
|
|
|
|
Logged
|
|
|
|
|
Malaysia
Offline
Newbie
Karma: 0
Posts: 19
Nobbie,first time
|
 |
« Reply #2 on: November 14, 2012, 10:33:07 am » |
I have added these libraries To the sketch,figured it out but thanks anyway!i was trying to do it on my own but times running out and I am desperate!!my project is exactly the same with the YouTube video Arduino Cemetry Howler Project,i got the hardware down,I need help with the software.I followed the guys links ,but where do I name the tracks? Plz help!!
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 313
Posts: 35507
Seattle, WA USA
|
 |
« Reply #3 on: November 14, 2012, 12:41:49 pm » |
but where do I name the tracks? I don't understand this question. The MP3 player library has a playTrack() method which plays the file named trackXXX.mp3 where XXX is supplied argument, or a playMP3() method that plays the named file.
|
|
|
|
|
Logged
|
|
|
|
|
Malaysia
Offline
Newbie
Karma: 0
Posts: 19
Nobbie,first time
|
 |
« Reply #4 on: November 14, 2012, 12:57:29 pm » |
Wat I mean is,in the SD card I name the track001.mp3,in the code where do I also name the track In the MP3 library?
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 313
Posts: 35507
Seattle, WA USA
|
 |
« Reply #5 on: November 14, 2012, 01:10:07 pm » |
Wat I mean is,in the SD card I name the track001.mp3,in the code where do I also name the track In the MP3 library? You can play that file using either: MP3player.playTrack(1); or MP3player.playMP3("track001.mp3");
|
|
|
|
|
Logged
|
|
|
|
|
Malaysia
Offline
Newbie
Karma: 0
Posts: 19
Nobbie,first time
|
 |
« Reply #6 on: November 14, 2012, 01:57:59 pm » |
I mean do I write playmp3"track00" where!!
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 313
Posts: 35507
Seattle, WA USA
|
 |
« Reply #7 on: November 15, 2012, 06:48:36 am » |
I mean do I write playmp3"track00" where!! What have you tried? The code you posted back at the beginning played a random track. Replacing the call to playTrack() with the call to playMP3(), to play a specific track, is trivial.
|
|
|
|
|
Logged
|
|
|
|
|
Malaysia
Offline
Newbie
Karma: 0
Posts: 19
Nobbie,first time
|
 |
« Reply #8 on: November 15, 2012, 07:23:06 am » |
Okok,based on the code I posted earlier with the said libraries will the code work?i need some one to verify it first?
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 313
Posts: 35507
Seattle, WA USA
|
 |
« Reply #9 on: November 15, 2012, 09:41:31 am » |
Okok,based on the code I posted earlier with the said libraries will the code work? Yes. Whether it does what you want, or not, is a different question. Only you have the hardware, so only you can answer the new question. i need some one to verify it first? Why? You can verify it yourself.
|
|
|
|
|
Logged
|
|
|
|
|
Malaysia
Offline
Newbie
Karma: 0
Posts: 19
Nobbie,first time
|
 |
« Reply #10 on: November 15, 2012, 10:11:48 am » |
I can't tell whether the codes are in order,cause i got them online and I fun know programming!all the code suppose to do is receive the input for the PIR sensor and activate a random track on the shield
|
|
|
|
|
Logged
|
|
|
|
|
|