Forum Discussion
Door Keypad Interaction
Hi Christina,
In the attached example, I have created five variables, Keypress, Keypress1, Keypress2, Keypress3 and Keypress4, which are set to 0, -1, -1, -1 and -1 respectively. I have also placed 100% transparent rectangles over each of the buttons on the keypad.
When the user clicks on a number on the keypad, Keypress is set to the value of that button and then Keypress1 is set to the value of Keypress provided Keypress1 = -1. If Kepress1 > -1 (i.e. it already has a number allocated to it), Keypress2 is set to the value of Keypress provided Keypress1 > -1 AND Keypress2 = -1 and so on.
This ensures that each click allocates a number in sequence until four numbers have been selected. At this point, if the correct sequence of numbers has been keyed in (in my example that is 2 4 6 8) the green light comes on and the red light goes out, signifying that the door has been unlocked.
The Reset button resets all variables and re-locks the safe. The Correct Code button (for those who can't crack it) shows the correct code and unlocks the safe.
I have also set up the Keypress 1-4 variables to be displayed above the keys on the keypad when their value changes, so that the user can see the code they have entered.
Hope this helps.
If you want, I can share my story file once I have the whole thing done and you can use it should you find a need.
- NedWhiteley6 years agoCommunity Member
Hi Christina,
I'm glad it worked out. Yes, I would love to see the end result when you have it all sorted.
Thanks