I am making a game and need my program to play a song when an object passes through the laser and makes the arduino read a value of 0. The problem I am having is that the song will not play except for the split second that the object interrupts the laser. I have researched this for about 6 hours and I feel like there is a simple solution but I am at a loss. Here is my code so far, please help.
#include "SD.h" #define SD_ChipSelectPin 10 #include "TMRpcm.h" #include "SPI.h"
int Laser = 6;
int Detector = 7;
TMRpcm tmrpcm;
This isn't right. If the SD fails to initialize then you set the pinMode for Laser. But if the SD does initialize then you don't set the pinMode for Laser.
PaulS:
Why do you need to turn the laser on on EVERY pass through loop()?
boolean val = digitalRead(Detector);
The digitalRead() function does not return a boolean.
The TMRpcm instance has a stupid name.
The TMPpcm library has a method to tell you if there is a song playing. Seems like a useful method to me.
thanks for the input Paul. I am very much a beginner but I think I grasp most of what you are saying. I have had to piece together this code the best I can from sources on the internet and my limited knowledge of coding. How do I go to the TMPpcm library to find the method that will tell the program that a song is playing?