Im working on a project that uses a LM393 Sound Detection Sensor. What i want to happen is the module will detect when im talking but once im done it will play my audio file automatically. I should have everything wired correctly i think im just running into a coding issue.
What is currently happening is when i talk and it detects my voice it will automatically play the audio file. It wont wait until im done talking.
Here is my code and some photos.
const int buttonPinStatic = 7; // Static
// variables will change:
int buttonState = HIGH; // variable for reading the pushbutton status
void setup() {
// initialize the button pin as a input:
pinMode(buttonPinStatic, INPUT);
// initialize serial communication:
Serial.begin(9600);
Serial.write(0x7E);
Serial.write(0x03);
Serial.write(0xA7);
Serial.write(0x1F); // volume max
Serial.write(0x7E);
// start sound
Serial.write(0x7E);
Serial.write(0x04);
Serial.write(0xA0); // A0 for SD card
Serial.write((byte)0x00);
Serial.write(0x02); // track number
Serial.write(0x7E);
delay(3000);
}
void loop()
{
Serial.write(0x7E);
Serial.write(0x02); //STOP Sound
Serial.write(0xA4);
Serial.write(0x7E);
buttonState = digitalRead(buttonPinStatic);
if (buttonState == HIGH) {
Serial.write(0x7E);
Serial.write(0x04);
Serial.write(0xA0); // A0 for SD card
Serial.write((byte)0x00);
Serial.write(0x01); // track number
Serial.write(0x7E);
delay(1000);
}
}