Hey guys im having issues and was hoping some one with more experience than I could tell me were i went wrong…
I am having trouble using more than one shield at a time
I am attempting to use the following:
mega 2560 (http://osepp.com/products/arduino-compatible-boards/osepp-mega-2560-arduino-compatible/)
with a music shield (http://www.seeedstudio.com/wiki/Music_Shield_V2.0)
and an LCD shield (http://osepp.com/products/shield-arduino-compatible/16x2-lcd-display-keypad-shield/)
I am able to use each shield individually but not together…
see my current sketch bellow
#include <PN532.h>
#include <SPI.h>
#include <LiquidCrystal.h>
#include <Fat16.h>
#include <Fat16Util.h>
#include <NewSPI.h>
#include <arduino.h>
#include "pins_config.h"
#include "vs10xx.h"
#include "newSDLib.h"
#include "MusicPlayer.h"
int lcd_key = 0;
int adc_key_in = 0;
int aux = 22; // the assined pin that signals Aux
int ledr = 53; // the assined pin that signals RED LED's
int ledy = 52; // the assined pin that signals Yellow LED's
int ledg = 51; // the assined pin that signals Green LED's
int starttime = 300; // amuont of time for game start count down in seconds
int gametimer = 30; // amount of game time in minuts
int buzz = 31; // the assigned pin that signals the buzzer
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
MusicPlayer myplayer;
void setup(void)
{
Serial.begin(9600);
myplayer.begin(); // will initialize the hardware and set default mode to be normal.
lcd.begin(16,2); // will initialize the hardware
lcd.setCursor(0,0); // will set lcd cursor to top left
lcd.print("Lets get it on!"); // print a simple message
delay (1000); // wait 1 seconds
lcd.setCursor(1,1); // sets cursor to second line and over 1 space
lcd.print("30 Min Game"); // displayes message
delay(5000); // waits 5 seconds
lcd.clear(); // clear LCD
pinMode(aux, OUTPUT); // gets aux pin ready for output
pinMode(ledr, OUTPUT); // gets red LED pin ready for output
pinMode(ledy, OUTPUT); // gets yellow LED pin ready for output
pinMode(ledg, OUTPUT); // gets green LED pin ready for output
}
void loop(void)
{
myplayer.setPlayMode(MODE_NORMAL); //set mode to repeat to play a song
while(starttime > 0)
{
lcd.setCursor(0,0); // sets LCD cursour to top left
lcd.print("Start In "); // displays a message
lcd.setCursor(1,1); // sets cursor to second line and over 1 space
lcd.print(starttime); // displays time left till game start
myplayer.playSong("danger.wav"); // play a file named with danger.wav
while(1); // If the music shield mode is normal, it will stop when it finished playing
digitalWrite(ledr, HIGH); // turns the red LEDs on
digitalWrite(ledy, HIGH); // turns the yellow LEDs on
digitalWrite(ledg, HIGH); // turns the green LEDs on
delay(1000); // delays 1 second
starttime -=1; // reduces the value of time by 1 after the delay listed above
break;
}
lcd.clear();
while(starttime < 1 )
{
digitalWrite(buzz, HIGH); // turns buzzer on
delay(1000); // delays for 1 seconds
digitalWrite(buzz, LOW); // turns buzzer off
digitalWrite(ledr, LOW); // turns red LEDs off
digitalWrite(ledy, LOW); // turns yellow LEDs off
digitalWrite(ledg, LOW); // turns green LEDs off
while(gametimer > 0)
{
digitalWrite(ledg, HIGH); // turns green LEDs on
lcd.clear(); // cleas lcd screen
lcd.setCursor(0,0); // sets the LCD cursor to top left
lcd.print("Device Detonates"); // displays message
lcd.setCursor(1,1); // sets cursor to second line and over 1 space
lcd.print("In "); // displays message
lcd.setCursor(5,1); // sets lcd cursor 5 spaces right and on 2nd row
lcd.print(gametimer); // displays tinme left in game
lcd.setCursor(9,1); // set cursor to 9 spaces left on second row
lcd.print("min"); // displays message
gametimer -=1; // reduces game timer by 1 afert the one second delay above
delay(60000); // delay for 1 min
break;
}
while(gametimer < 21)
{
myplayer.playSong("20min.wav"); // play a file named 20min.wav
while(1); // If the music shield mode is normal, it will stop when it finished playing
digitalWrite(ledy, HIGH); // turns yellow LEDs on
break;
}
while(gametimer < 11)
{
myplayer.playSong("10min.wav"); // play a file named 10min.wav
while(1); // If the music shield mode is normal, it will stop when it finished playing
digitalWrite(ledr, HIGH); // turns red LEDs on
break;
}
while(gametimer < 1)
{
lcd.clear(); // clears lcd screen
lcd.setCursor(0,0); // sets lcd cursor to top letf
lcd.print(" GAME --- OVER"); // displays a message
digitalWrite(buzz, HIGH); // starts buzzer
digitalWrite(aux, HIGH); // send signal to relay a.k.a AUX
delay(5000); // delays for 5 seconds
digitalWrite(aux, LOW); // stops signal to relay a.k.a AUX
delay(5000); // delays for 5 seconds
digitalWrite(buzz, LOW); // turns buzzer off
myplayer.playSong("over.wav"); // play a file named over.wav
}
}
}
_30min_countdown.ino (7.93 KB)