Project 12 (Knock Lock)

Hi.

I think there is a problem in the code for project 12 (or the example only works the first time for me).

I lock the box pressing the switch and unlock it knocking 3 times. But when I try lo lock it again pressing the switch, it gets unlocked without waiting for the the knocks. In the communication window, I can see:

the box is unlocked!
the box is locked!
the box is unlocked!
the box is locked!
the box is unlocked!

Upon the variable numberOfKnocks is greater than 3, the code never enters line 39 again, and always satisfies line 46 and, consecuently, it gets unlocked automatically.

If I insert in line number 53 numberOfKnocks=0; (when it gets unlocked), then it works for me.

Anyone can verify it?

Thanks.

I have the same

Hello everyone, I just realized this project, but the first time it works correctly, but after knocking on it with pressing the button piezo continues unlock. I tried to add a delay () but I get the same problem.
Someone was able to find the solution?

Hi!

Here is how i fixed it:

http://forum.arduino.cc/index.php?topic=175831.msg1383787#msg1383787

thank!!!! the new line work perfect :slight_smile: