Last active
December 17, 2015 06:59
-
-
Save mpflaga/5569322 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// libraries | |
#include <SPI.h> | |
#include <SdFat.h> | |
#include <SdFatUtil.h> | |
#include <SFEMP3Shield.h> | |
// initialize MP3 card | |
SdFat sd; | |
SFEMP3Shield MP3player; | |
// constant variables | |
int inputPin = 0; // IR sensor input pin | |
unsigned long pauseTime = 5000; // how long the pause will be after music turned off | |
int readingInterval = 10; // interval to read the sensor | |
int SignalPin = 5; | |
int SignalPin2 = 4; | |
#define SignalPin 5 | |
#define SignalPin2 4 | |
// setup | |
void setup() { | |
Serial.begin(9600); | |
sd.begin(SD_SEL, SPI_HALF_SPEED); | |
MP3player.begin(); | |
MP3player.setVolume(10, 10); | |
pinMode(inputPin, INPUT); | |
pinMode(SignalPin, INPUT); | |
} | |
// loop | |
void loop(){ | |
int Signal; | |
if (analogRead(inputPin) > 450) { | |
play(2); | |
} | |
Signal = digitalRead(SignalPin); | |
if (Signal == 1){ | |
Serial.print (Signal); | |
Serial.println(“ no obstacle”); | |
} | |
else { | |
play(1); | |
} | |
Signal = digitalRead(SignalPin2); | |
if (Signal == 1){ | |
Serial.print (Signal); | |
Serial.println(“ no obstacle”); | |
} | |
else { | |
play(2); | |
} | |
delay(readingInterval); // wait with reading | |
} | |
void play(uint8_t track) { | |
//MP3player.stopTrack(); | |
MP3player.playTrack(track); | |
while(MP3player.isPlaying()) { | |
//wait until done playing | |
} | |
delay(pauseTime); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment