project 12 Arduino Starter Kit, Knock Lock

Dear all

I am trying to work on project 12 Knock Lock, and I think there must be a problem with the Piezo Buzzer I am using (or the code provided on the book!)

I include the function here below:

// this function checks to see if a  
// detected knock is within max and min range
boolean checkForKnock(int value){
  // if the value of the knock is greater than
  // the minimum, and larger than the maximum
  if(value > quietKnock && value < loudKnock){
    // turn the status LED on
    digitalWrite(yellowLed, HIGH);
    delay(500);
    digitalWrite(yellowLed, LOW);
    // print out the status
    Serial.print("Valid knock of value ");
    Serial.println(value);
    // return true
    return true;
  }
  // if the knock is not within range
  else {
    // print status
    Serial.print("Bad knock value ");
    Serial.println(value);  
    // return false
    return false;
  }
}

The problem I am facing is, when the Piezo detects the correct value (say 23) from a single knock, the program goes into turning on the yellow LED. That is fine. But I can observe on my Serial Monitor the knockVal showing 23 (or 24) endlessly in the loop without returning back to zero (and the yellow LED never gets turned off) ! Somehow when I removed :

    digitalWrite(yellowLed, HIGH);
    delay(500);
    digitalWrite(yellowLed, LOW);

the knockVal did return to Zero after the single knock on the Piezo.

it is very bizzare! can anyone explain to me what happened please?

Thanks!

update: when I changed the delay value to 10 (see below) it works! (the knockVal returned to zero) why didn't delay(500) work??

  digitalWrite(yellowLed, HIGH);
    delay(10);
    digitalWrite(yellowLed, LOW);

Anyone has an idea why delay (500) didn't work please? I am really bothered by this ...