Alright!
I have learned sooo much as a beginner. (well, as much as a full time employee with a family can learn)
I have had some great help along the way. (Thank you Mark)
I STILL can not get the MP3 player to play.
I get a generic error msg in my Serial Monitor.
"If you get this error, you likely do not have a sd.begin in the main sketch, See Trouble Shooting Guide!
http://mpflaga.github.com/Sparkfun-MP3-Player-Shield-Arduino-Library/#Troubleshooting
"
Bugs are good for Halloween... just not with this.
If you notice anything else that I need to address please please point it out! All help is appreciated!
// Haunted Tree
//No telling how many of those can be deleted...
#include <Servo.h>
#include <ArduinoStream.h>
#include <bufstream.h>
#include <ios.h>
#include <iostream.h>
#include <istream.h>
#include <MinimumSerial.h>
#include <ostream.h>
#include <Sd2Card.h>
#include <SdBaseFile.h>
#include <SdFat.h>
#include <SdFatConfig.h>
#include <SdFatmainpage.h>
#include <SdFatStructs.h>
#include <SdFatUtil.h>
#include <SdFile.h>
#include <SdInfo.h>
#include <SdSpi.h>
#include <SdStream.h>
#include <SdVolume.h>
#include <SPI.h>
#include <SFEMP3Shield.h>
#include <SFEMP3ShieldConfig.h>
#include <SFEMP3Shieldmainpage.h>
SFEMP3Shield MP3player;
SdFat sd;
// input pins
#define PIR1 A1
// output pins
Servo CROW1;
Servo CROW2;
#define FX1 0
#define CROWLED 4
#define CLOWNSWING 1
#define FALLINGLIMB A5
#define OWLHOLE 10
#define STUMPJUMP A4
#define STUMPLED A3
#define SCK 13
#define MISO 12
#define MOSI 11
#define CS 9
#define XRESET 8
#define XDCS 7
#define XCS 6
#define DREQ 2
// other global defines and variables
#define N_EFFECTS 6
int pos = 0; // variable to store the servo position
byte last_effect=0; //Cause I was told to
/////////////////////////////
// code start
/////////////////////////////
// effect #0
void boo() {
Serial.print("BOO!\n");
// sample flash code
for (byte i=0;i<6;i++)
{
digitalWrite(FX1,HIGH);
delay(100);
digitalWrite(FX1,LOW);
delay(100);
}
}
//Crows
//Crow1
void Crows(){
MP3player.playTrack(001); //play crow caws
Serial.print("Crow1\n");
digitalWrite(CROWLED, HIGH);
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
CROW1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
CROW1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
CROW1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
CROW1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
CROW1.write(90);
//Crow2
Serial.print("Crow2\n");
for (pos = 0; pos <= 180; pos += 1){ // goes from 0 degrees to 180 degrees
// in steps of 1 degree
CROW2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) // goes from 180 degrees to 0 degrees
CROW2.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
CROW2.write(25);
digitalWrite(CROWLED, LOW);
delay(4000);
}}}
//ClownSwing
void ClownSwing(){
Serial.print("ClownSwing\n");
digitalWrite (CLOWNSWING, LOW);
digitalWrite (CLOWNSWING, HIGH); //activate tryme button on prop
delay(100);
digitalWrite (CLOWNSWING, LOW);
delay(4000);
}
//FallingLimb
void FallingLimb(){
Serial.print("FallingLimb\n");
MP3player.playTrack(003); //play falling limb sound and screams
digitalWrite(FALLINGLIMB, HIGH); // turn the solenoid on Limb Falls
delay(20000); // wait for a second or twenty
digitalWrite(FALLINGLIMB, LOW); // turn the solenoid off
delay(1000); // wait for a second
}
//Spiders
void Spiders(){
Serial.print("EEK! SPIDERS!\n");
MP3player.playTrack(004);
//spiders1
//drive motor forward 5 seconds
//stop
//drive revers 5 second
//stop
//spiders2
//drive motor forward 2 seconds
//stop
//drive motor forward 3 seconds
//stop
//revers 2 seconds
//forward 1 second
//revers 4 seconds
delay(1000);
}
//OwlHole
void OwlHole(){
Serial.print("Owl\n");
MP3player.playTrack(005); //play Owl hoots
digitalWrite(OWLHOLE, LOW);
digitalWrite(OWLHOLE, HIGH); //activate LED's to backlight owl in hole
delay(1000);
digitalWrite(OWLHOLE, LOW);
delay(600);
digitalWrite(OWLHOLE, HIGH);
delay(1000);
digitalWrite(OWLHOLE, LOW);
delay (4100);
digitalWrite(OWLHOLE, HIGH);
delay (2000);
digitalWrite(OWLHOLE, LOW); //thats what i think an Owl hoot will look like
delay(3000);
digitalWrite(OWLHOLE, HIGH); //activate LED's to backlight owl in hole
delay(1000);
digitalWrite(OWLHOLE, LOW);
delay(200);
digitalWrite(OWLHOLE, HIGH);
delay(1000);
digitalWrite(OWLHOLE, LOW);
delay (300);
digitalWrite(OWLHOLE, HIGH);
delay (2000);
digitalWrite(OWLHOLE, LOW);
delay (4000);
}
//Stump
void StumpJump() {
Serial.print("Stump\n");
MP3player.playTrack(006); //play scream scare
digitalWrite(STUMPJUMP, HIGH); // turn the solenoid on Limb Falls
digitalWrite(STUMPLED, HIGH);
delay(20000); // wait for a second or twenty
digitalWrite(STUMPJUMP, LOW); // turn the solenoid off
delay(1000); // wait for a second
digitalWrite(STUMPLED, LOW); //I will have flow control on line .Keep it lit while retracts
delay(4000);
}
void nothing(){
if (digitalRead(PIR1) == LOW){
Serial.print("DID YOU HEAR THAT?\n");
MP3player.playTrack(007); //play ambiant music when not scaring ppl (might as well do something while its doing nothing)
}}
// add more effect routines
// no, no more...I just cant right now
// end effect routines
//////////////////////////////
byte generateEvent() {
byte ev=last_effect;
while (ev==last_effect)
ev=random(N_EFFECTS);
return ev;
}
/////////////////////////////
/////////////////////////////
void setup()
{
Serial.begin(9600); // open the serial port at 9600 bps:
Serial.print("You turned me on.\n");
Serial.print("sd begin\n");
sd.begin();
delay(1000);
MP3player.begin();
Serial.print("MP3 Begin\n");
delay(1000);
MP3player.setVolume(40, 40);
delay(2000);
pinMode(PIR1,INPUT);
pinMode(FX1,OUTPUT);
pinMode (CLOWNSWING, OUTPUT);
pinMode (FALLINGLIMB, OUTPUT);
pinMode (OWLHOLE, OUTPUT);
pinMode (STUMPJUMP, OUTPUT);
pinMode (STUMPLED, OUTPUT);
CROW1.attach(5);
CROW2.attach(3);
pinMode(MP3_DREQ, INPUT);
pinMode(MP3_XCS, OUTPUT);
pinMode(MP3_XDCS, OUTPUT);
pinMode(MP3_RESET, OUTPUT);
randomSeed(analogRead(8)); //Is this the number of scares?
}
void loop() {
byte effect;
if (digitalRead(PIR1))// throw a ! in front of the digital Read if the signal goes low when active
{
effect = generateEvent();
switch (effect) {
case 1:
Crows();
break;
case 2:
ClownSwing();
break;
case 3:
FallingLimb();
break;
case 4:
Spiders();
break;
case 5:
OwlHole();
break;
case 6:
StumpJump();
break;
case 7:
boo();
break;
default:
nothing();
}// end switch case
}// end if PIR sensor
}// end main loop
/////////////////////////////
//This sketch started 9/22/2015
//Thank you Mark MacDonald! You Rock!!!