Hi and thanks for reading. I am new to Arduino and am using the uno.
I have some knowlage of picbasic and have enjoyed the transition to Arduino but im having problems.
My project requires me to detect when a button is pressed and play a sound, I have managed to do this and have posted the code below but what I need to do is play a different sound each time the same button is pressed for 3 tries and light a separate led each time, then play a fourth sound and switch a relay on, wait 20 seconds and then return to the start. I keep finding that im using basic commands and obviously this don't work, any help/direction with this would be greatly appreciated.
My code is as follows :
const int resetPin = 2; // The pin number of the reset pin.
const int clockPin = 3; // The pin number of the clock pin.
const int dataPin = 4; // The pin number of the data pin.
const int busyPin = 5; // The pin number of the busy pin.
const int fireButtonPin = 6; // The pin number of the fire button pin.
int busyPinState = HIGH;
int fireButtonPinState = LOW;
void setup() {
pinMode(resetPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(busyPin, INPUT);
pinMode(fireButtonPin, INPUT);
digitalWrite(resetPin, HIGH);
digitalWrite(clockPin, HIGH);
digitalWrite(dataPin, LOW);
}
void loop() {
fireButtonPinState=digitalRead(fireButtonPin);
if (fireButtonPinState==HIGH){
playSong(0x0007);
}
}
void playSong(int trackNumber){
resetModule();
sendCommand(trackNumber);
busyPinState=digitalRead(busyPin);
while(busyPinState==HIGH){
busyPinState=digitalRead(busyPin);
}
}
void resetModule(){
digitalWrite(resetPin, LOW);
delay(5);
digitalWrite(resetPin, HIGH);
delay(400);
}
void sendCommand(int address)
{
digitalWrite(clockPin, LOW);
delay(2);
for (int mask=15; mask>=0; mask--)
{
delayMicroseconds(200);
if((address>>mask)&0x0001 >0)
{
digitalWrite(dataPin, HIGH);
}
else
{
digitalWrite(dataPin, LOW);
}
delayMicroseconds(200);
digitalWrite(clockPin, HIGH);
delayMicroseconds(200);
if(mask>0)
{
digitalWrite(dataPin, LOW);
}
else
{
digitalWrite(dataPin, HIGH);
delayMicroseconds(200);
}
if(mask>0)
{
digitalWrite(clockPin, LOW);
}
else
{
digitalWrite(clockPin, HIGH);
}
}
delay(30);
}