#include <SdFat.h>
#include <SdFatUtil.h>
#include <SPI.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
}
}
this is the code i have compiled to randomly play any track when motion is detected,all of it i found online!
now i am going to name the tracks in the SD card track000.mp3 and etc. The problem i am having is where do i change in the code for these names?? I got the libraries online.
I am on a deadline and a prompt answer is very much appreciated
Thanks ,Newbie