Outils pour utilisateurs

Outils du site


issue89:arduino

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.

Le mois dernier j'ai parlé de la fusion de deux essais en un seul ayant pour résultat l'affichage sur un écran LCD de la frappe des touches du clavier. Ce mois-ci je garde le même circuit, mais en ajoutant plus de code.

Bienvenue !

Je pensais que ce serait bien si l'Arduino pouvait prendre la saisie du clavier et vérifier un mot de passe connu. Eh bien, il y a justement une bibliothèque élégante et pratique appelée Password. Vous pouvez la charger à partir de : http://playground.arduino.cc/Code/Password

Comme il est indiqué sur la page, téléchargez, décompressez et copiez le dossier dans votre dossier de bibliothèques d'essais. Maintenant, vous pouvez utiliser :

#include <Password.h>

dans votre code.

Fusionner le code s'avérait difficile jusqu'à ce que je trouve cet exemple :

https://sites.google.com/site/arduinomega2560projects/home/level-3/keymembrane-and-lcd-password-lock C'est à peu près ce que je voulais faire, mais avec mon clavier 3×4.

Après beaucoup de bricolage, j'ai réussi à le faire fonctionner. Une chose qui m'a préoccupé pendant un certain temps a été les arguments « include ». Apparemment, on ne doit rien mettre entre les lignes d'inclusion. J'avais la ligne Password(“4321”) directement sous la ligne d'inclusion de Password, mais avant la ligne d'inclusion de LiquidCrystal et ça m'a rendu perplexe un certain temps. Une fois cela réglé, je ne comprenais pas pourquoi il n'acceptait pas le mot de passe.

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…?

Après beaucoup de tâtonnements, j'ai trouvé ceci dans la ligne :

case ' ': guessPassword(); break;

L'instruction « case ‘ ‘ » est en fait la touche « Entrée » pour le mot de passe. Ainsi, changer le ‘ ‘ en '#' a fonctionné très bien. Après ça j'ai rendu les écrans d'avant et d'après plus propres.

Maintenant, il dit : « Entrez le code : ». Vous entrez un code à quatre chiffres et appuyez sur la touche dièse (#) pour terminer. L'écran LCD dira soit « INVALID PASSWORD », pause, et reviendra à l'écran « Entrez le code : », soit « VALID PASSWORD», pause et affichera « Welcome! », pause, puis reviendra à l'écran « Entrez le code : ».

Mon code est ici: http://pastebin.com/V0f9GBFf

Bon, est-ce que ça ne serait pas mieux s'il s'arrêtait à « Welcome! » et attendait que quelque chose se passe avant d'avoir besoin d'un code ou autre… ?

issue89/arduino.txt · Dernière modification : 2015/02/06 14:48 de andre_domenech