In the firsts prints of the book, the code shown had a typo where the “knock counter” variable was not reset to 0 after the first “unlock”, hence this issue would happen.
Code
This issue is fixed in the IDE example, but it’s worth to check before uploading to your board.