Hi everyone,
I am trying to trigger a single sample off the Sparkfun Mp3 player shield using a sensor as input. In this example I am talking about the E18-d80NK, as it returns just 0's and 1's as opposed to going through conditional statements or whatever using a rangefinder etc, but I have a number of other sensors so if you think it will work better with one of them I am open to suggestions. I have got the sample loaded and mp3 shield working with example patches, and the sensor working, but both in isolation of each other.
I have done similar things before, but always interfaced with maxuino and this time that is not an option. I have been going crazy trying to make it work for over a week but so far no luck, even using the various other very similar projects posted around the web.
This is where I have got to splicing various other pieces together, I tried to go step by step as simple as possible but it just wont work, I figured it was time to ask the experts!
// libraries
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
// initialize MP3 card
SdFat sd;
SFEMP3Shield MP3player;
// constant variables
int inputPin = 5; // IR sensor input pin
unsigned long pauseTime = 10000; // how long the pause will be after music turned off
int readingInterval = 10; // interval to read the sensor
// changing variables
int trigger = 1; // variable for pin status
byte result; // variable for mp3 player shield, can be used to debug
// setup
void setup() {
pinMode(inputPin, INPUT); // make sensor an input
digitalWrite(inputPin, HIGH); // activate internal pull-up resistor
result = MP3player.begin(); // start mp3 player shield
MP3player.setVolume(10, 10); // set volume of the mp3 player
}
// loop
void loop(){
trigger = digitalRead(inputPin); // read sensor
if (trigger == 0) { // if sensed
result = MP3player.playTrack(1); // play track
delay(pauseTime); // wait...
}
delay(readingInterval); // wait with reading
}
Thanks in advance, too much sleep has already been lost.
Jack