Hi! So I'm creating a small project wherein I have a wooden kitchen that has doors to an oven, washing machine and microwave ect. when the doors are closed, they will press against a button. when they are open, (button is unpressed, low) I want them to trigger a sound corresponding to whatevers being opened. e.g. a ping when microwave opens.
I have one 8ohm speaker and four buttons to activate 4 separate 10 second sounds. thing is, with how i have written this programme (unfinished) will the sounds repeat continuously when the doors are left open? I just want the sound to play once until the door is closed then opened again. and will one speaker with 4 inputs work like this? the sounds are 10 seconds so will i need to put a delay on of sorts to hold it? I can't fully test this out yet as still waiting for some parts but
any advice is welcome please, i'm totally new to programming but know a good thing or two on electrics, thanks!
#include "SD.h"
#define SD_ChipSelectPin 4
#include "TMRpcm.h"
#include "SPI.h"
const int stovebutton1 = 2;
const int stovebutton2 = 3;
const int microwavebutton= 4;
const int washerbutton = 5;
pinMode(stovebutton1, INPUT);//boiling sound
pinMode(stovebutton2, INPUT);//frying sound
pinMode(microwavebutton, INPUT);//ding sound
pinMode(washerbutton, INPUT);//washing sound
TMRpcm tmrpcm;
void setup(){
tmrpcm.speakerPin = 9;
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");
return;
}
tmrpcm.setVolume(6);
}
void loop(){ }
// read the state of the pushbutton value:
buttonState = digitalRead(stovebutton1);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == LOW) {
// turn boiling sound on
tmrpcm.setVolume(6);
tmrpcm.play("boiling.wav");
}
buttonState = digitalRead(stovebutton2);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == LOW) {
// turnfrying sound on
tmrpcm.setVolume(6);
tmrpcm.play("frying.wav");
}
buttonState = digitalRead(microwavebutton);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == LOW) {
// turn boiling sound on
tmrpcm.setVolume(6);
tmrpcm.play("ding.wav");
}