4 pushbutton lock coding [SOLVED]

I agree that clarifying the state machine will help to solve this problem pretty quickly, so I have attached a sample state diagram. You must be logged in to see the attached GIF image. The boxes are states. The lines are transitions between states, caused by button press events. One thing that came to my mind while reading this forum thread is that you were not accounting for the fact that you do not want to show the person whether the entire set of 4 button presses is correct or incorrect until after all 4 buttons have been pressed. This is a standard way of preventing the person from learning the passcode just by pressing random buttons. So, you should not light any LEDs until all 4 buttons are pressed, represented by the "Correct" and "Incorrect" states in the diagram.

If you implement this diagram using a single variable to hold the state identifier, and always check for a button press in the loop, based on the current state, then there is no need to wait for anything. The delays are inherent. The only time a delay is needed is when lighting the LED for an amount of time, and of course, you can use the state variable and a clock time variable to know when to turn off the LED, so your code does not need any delay statements at all.

Hope that helps. :slight_smile: