I'm building a portal gun from the game Portal and I'm struggling with the wiring for the lights and sound. I've the lights working using the first image from Instructables and adding more LEDs shouldn't be a problem. I'm trying to add the SD card and speaker so when you flick the switch, as well as the lights changing, the firing sound is played. Image 2. everything is wired quite nicely the only change is I'm using pin 10 not 4 on the memory card.
This is my code and it all compiles fine and seems to make sense to me but I'm new to programming.
The lights work but none of the sounds play. I've formatted the SD card and also made sure the .wav files are the right format: mono 8 bit 16000 Hz. I can't work out what's wrong and why I can't get it to play the sounds.
I also have an Adafruit amp just in case it isn't loud enough but not a clue how to wire it in.
#include <pcmRF.h>
#include <TMRpcm.h>
#include <SD.h> // need to include the SD library
#define SD_ChipSelectPin 10 // using digital pin 10 on arduino uno 328, can use other pins
#include <SPI.h>
void setup()
{
// put your setup code here, to run once:
TMRpcm tmrpcm;
tmrpcm.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin))
{
Serial.println("SD fail");
return;
}
tmrpcm.setVolume(6);
tmrpcm.play("1.wav");
tmrpcm.play("2.wav");
//set the switch input, pin 8, as an
pinMode(8, INPUT);
//set both the LED pins, pin 5 and 6 as OUTPUTs
pinMode (5, OUTPUT);
pinMode (6, OUTPUT);
}
void loop()
{
TMRpcm tmrpcm;
int switchValue = digitalRead(8);
if (switchValue == 1)
{
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
tmrpcm.setVolume(6);
tmrpcm.play("4.wav");
}
else
{
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
tmrpcm.setVolume(6);
tmrpcm.play("5.wav");
}
}

