Hi all. I have attached the adafruit mp3 music maker shield to the mega and used their player_simple sketch. Everything works as it should with two tracks being played. I have included my code for my game I have been working on. It compiles fine but when I upload to the mega and push my buttons I hear nothing. I have been using the serial monitor to observe the button push on pin 15. I see the value in arr 1 change from 0 to 1. When I push another button it resets/changes back to 0 as expected. I think the problem is in how I am calling the music player??? Any help appreciated as always.
/***************************************************
This is an example for the Adafruit VS1053 Codec Breakout
Designed specifically to work with the Adafruit VS1053 Codec Breakout
----> https://www.adafruit.com/products/1381
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
// These are the pins used for the music maker shield
#define SHIELD_RESET -1 // VS1053 reset pin (unused!)
#define SHIELD_CS 7 // VS1053 chip select pin (output)
#define SHIELD_DCS 6 // VS1053 Data/command select pin (output)
#define CARDCS 4 // Card chip select pin
#define DREQ 3 // VS1053 Data request, ideally an Interrupt pin
Adafruit_VS1053_FilePlayer musicPlayer =
// create shield-example object!
Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
//Each pin has a switch to activate it. switchPin 15 (arr 1) makes a pair with switch 26 (arr 12). When each is pressed music player plays "homer000.mp3" and
//if both pressed music player than plays "excell00.mp3.
//If the switches do not match musicPlayer needs to play "failure01.mp3".
int switchPins[] = {14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,53, A8, A9, A10, A11, A12, A13, A14, A15};
int pinCount = 45;
bool arr[44];//variable to hold what switches were pressed
int switchOpenedCount = 45;
char* simpsonSounds [] = {"itchy000.mp3", "homer000.mp3", "willy000.mp3", "arpu0000.mp3", "itchy000.mp3", "mrburns0.mp3", "bart0000.mp3", "wigam000.mp3", "wigam000.mp3", "flanders.mp3", "lisa0000.mp3", "marg0000.mp3", "homer000.mp3", "marg0000.mp3", "lisa0000.mp3", "krusty00.mp3", "snowball.mp3", "itchy000.mp3", "maggie00.mp3", "nelson00.mp3", "milhouse.mp3", "milhouse.mp3", "nelson00.mp3",
"grandpa0.mp3", "snowball.mp3", "santa000.mp3", "bart0000.mp3", "maggie00.mp3", "milhouse.mp3", "krusty00.mp3", "grandpa0.mp3", "bartman0.mp3", "bartman0.mp3", "flanders.mp3", "santa000.mp3", "willy000.mp3", "fink0000.mp3", "mrburns0.mp3", "ralph000.mp3", "ralph000.mp3", "fink0000.mp3", "hans0000.mp3", "hans0000.mp3", "arpu0000.mp3", "itchy000.mp3",
};
//There are two other files on the card excell00.mp3 and failure0.mp3 not part of the above array.
void setup() {
SD.begin(CARDCS); // initialise the SD card
// Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(20, 20);
// Timer interrupts are not suggested, better to use DREQ interrupt!
//musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int
// If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
// audio playing
musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT); // DREQ int
Serial.begin(9600);
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(switchPins[thisPin], INPUT_PULLUP);
}
//turns all bool arr to false.
for (int switchOpen = 0; switchOpen < switchOpenedCount; switchOpen++) {
arr[switchOpen] = false;
}
}
void loop() {
int sensorValue = arr[1];//Used to test if button on pin 15 is registering the push.
Serial.println(sensorValue);
for (int thisPin = 0; thisPin < pinCount; thisPin++)
{
if (digitalRead(switchPins[thisPin]) == LOW)
{ arr[thisPin] = true;
musicPlayer.playFullFile(simpsonSounds[thisPin]);
}
}
//Repeat this logic for every pair of switches.
if (arr[1] == true)
{
if (arr[12] == true)
{ musicPlayer.playFullFile("excell00.mp3");
//set doors/arr back to false
for (int switchOpen = 0; switchOpen < switchOpenedCount; switchOpen++) {
arr[switchOpen] = false;
}
}
else
{
for (int thisPin = 0; thisPin < pinCount; thisPin++)
{
if (thisPin != 1 && thisPin != 12 && arr[thisPin] == true)
{ //doors do not match so play 'wrong' sound.
musicPlayer.playFullFile("failure0.mp3");
//set arr/doors back to false
for (int switchOpen = 0; switchOpen < switchOpenedCount; switchOpen++) {
arr[switchOpen] = false;
}
}
}
}
}
if (arr[12] == true)
{
if (arr[1] == true)
{ //doors match so play success sound
musicPlayer.playFullFile("excell00.mp3");
//set doors/arr back to false
for (int switchOpen = 0; switchOpen < switchOpenedCount; switchOpen++) {
arr[switchOpen] = false;
}
}
else
{
for (int thisPin = 0; thisPin < pinCount; thisPin++)
{
if (thisPin != 12 && thisPin != 1 && arr[thisPin] == true)
{ //doors do not match so play 'wrong' sound.
musicPlayer.playFullFile("failure0.mp3");
//set arr/doors back to false
for (int switchOpen = 0; switchOpen < switchOpenedCount; switchOpen++) {
arr[switchOpen] = false;
}
}
}
}
}
}