Hello All, I am just starting off with this fun little project and trying to piece together the different aspects of the sketch
the project aims to measure a quickdraw ie you turn on the device, the LCD has a welcome note, you press a button and a tone sounds, you draw your gun and shoot, the noise is detected and the duration between the sound starting and the shot is displayed in milliseconds, you press the button, it resets to the welcome screen until you press the button again and the tone sounds etc
so I am learning on the fly here and got this far with the sketch
//Arduino Sound Detection Sensor Module
// Declare the pins for the Button and the LED
int buttonPin = 12;
int LED = 13;
int soundDetectedPin = 3; // Use Pin 10 as our Input
int soundDetectedVal = HIGH; // This is where we record our Sound Measurement
boolean bAlarm = false;
unsigned long lastSoundDetectTime; // Record the time that we measured a sound
int soundAlarmTime = 500; // Number of milli seconds to keep the sound alarm high
// Buzzer - Version: Latest
#include <Buzzer.h>
//Sample using LiquidCrystal library
#include <LiquidCrystal.h>
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
Buzzer buzzer(11, 13);
void setup()
{
lcd.begin(16, 2); // start the library
lcd.setCursor(0, 0);
lcd.print("Merv's Digital "); // print a simple message
lcd.setCursor(0, 1);
lcd.print("Quickraw Device"); // print a simple message
// Define pin #12 as input and activate the internal pull-up resistor
pinMode(buttonPin, INPUT_PULLUP);
// Define pin #13 as output, for the LED
pinMode(LED, OUTPUT);
Serial.begin(9600);
pinMode (soundDetectedPin, INPUT) ; // input from the Sound Detection Module
}
void loop() {
// Read the value of the input. It can either be 1 or 0
int buttonValue = digitalRead(buttonPin);
if (buttonValue == LOW) {
// If button pushed, turn LED on
digitalWrite(LED, HIGH);
soundDetectedVal = digitalRead (soundDetectedPin) ; // read the sound alarm time
/* Serial.println(lastSoundDetectTime);
*/
if (soundDetectedVal == LOW) // If we hear a sound
{
lastSoundDetectTime = millis(); // record the time of the sound alarm
// The following is so you don't scroll on the output screen
if (!bAlarm) {
Serial.println("Bang");
lcd.setCursor(0, 0);
lcd.print("BANG! "); // print a simple message
lcd.setCursor(0, 1);
lcd.print(" "); // print a simple message
delay(5000);
lcd.setCursor(0, 0);
lcd.print("Merv's Digital "); // print a simple message
lcd.setCursor(0, 1);
lcd.print("Quickraw Device"); // print a simple message
bAlarm = true;
}
}
}
}
so I get the welcome screen and if I hold the button it listens for a loud sound, when detected it prints "bang" on the serial monitor and the LCD and then returns to the welcome screen but it will not run a second time when pressing the button and I need it to run one one press of the button not holding the button down
I cant see why this doesnt loop, I expect its obvious but any help would be appreciated
I will be adding the buzzer and timer after I have go this part solved
thanks
Dan