Outils pour utilisateurs

Outils du site


issue89:arduino

Ceci est une ancienne révision du document !


Last month was a merge of two sketches into one which resulted in keypad presses being displayed on an LCD screen. This month I’m keeping the same circuit but adding more code.

Welcome!

I thought it’d be nice if the Arduino could take the keypad input and check it against a known password. Well, there just happens to be a handy dandy library called Password. You can grab it from: http://playground.arduino.cc/Code/Password.

As it says on the page, download, unarchive and copy the folder to your sketches library folder. Now you can use

#include <Password.h>

in your code.

Merging the code wasn’t going so well for me until I found this example:

https://sites.google.com/site/arduinomega2560projects/home/level-3/keymembrane-and-lcd-password-lock. This is pretty much what I wanted to achieve – but with my 3×4 keypad.

After much tinkering, I managed to get it working. One thing that did catch me out for a while was the include statements. Apparently you shouldn’t put things between the include statements. I had the Password(“4321”) line right below the Password include, but before the LiquidCrystal include, so that stumped me for a bit. Once I got past that, I got stumped with why it wouldn’t accept the password. After much trial and error I found that in the line:

case ' ': guessPassword(); break;

the “case ‘ ‘“ statement is effectively the ‘enter’ key for the password. So, changing the ‘ ‘ to ‘#’ worked a treat. After that I tidied up the before and after screens.

Now it says ‘Enter code:’. You enter a four digit code and press the hash key (#) to finish. The LCD screen will either say ‘INVALID PASSWORD’, pause, and return to the ‘Enter code:’ screen, or it will say ‘VALID PASSWORD’, pause, display ‘Welcome!’, pause, then return to the ‘Enter code:’ screen.

My code is at: http://pastebin.com/V0f9GBFf.

Now, wouldn’t it be nice if it stopped at ‘Welcome!’ and waited for something to happen before needing a code or something…?

issue89/arduino.1414776748.txt.gz · Dernière modification : 2014/10/31 18:32 de andre_domenech