Sound detection Code

So I'm trying to make a LED turn on when sound is being detected by the sound sensor module and not turn off untill sound is being detected again. The following code used to work just fine, but it doesn't anymore, and I wonder why that is


#define LED 13
#define SOUNDDETECT 10
int soundDetectedVal = HIGH;
unsigned long lastSoundDetectTime;
int soundAlarmTime = 500;
boolean bAlarm = false;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode (SOUNDDETECT, INPUT);
pinMode (LED, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
if (soundDetectedVal == LOW){
lastSoundDetectTime = millis();
if (!bAlarm){
Serial.println("LOUD");
bAlarm = true;
digitalWrite(LED, !digitalRead(LED));
}
}
else
{
if( (millis()-lastSoundDetectTime) > soundAlarmTime && bAlarm){
Serial.println("quiet");
bAlarm = false;
}
}
}


Thanks

PS: I'm new here, sorry if I did anything in a way it shouldn't be done.

No, that code has never worked. It doesn't ever read anything from the SOUNDDETECT pin.

Steve

Oh, thanks, must have remebered it wrong then. This helps a lot.