
Componenti necessari:
- Arduino
- matrix keypad (il mio è un 4x4 a membrana, tipo questo).
- 4 resistori di pull up da 10kΩ
La libreria da utilizzare con arduino la trovate sul sito ufficiale: keypad matrix library
Il componente keypad matrix 4x4 per Fritzing l'ho creato modificando la versione 3x4 che si scarica da qui.
[UPDATE-20130731]:
Un classico esempio di utilizzo del tastierino e della libreria, il codice lo potete trovare anche qui.
Controllo accesso con password (la password viene testata automaticamente all'immissione dell'ultimo carattere, ma si può implementare in mille altri modi):
/* @original file HelloKeypad.pde
|| @version 1.0
|| @original author Alexander Brevig
|| @editor Daniele Forti (aka willygroup)
||
|| @description
|| | Demonstrates use of the matrix Keypad library in "checking password".
|| #
*/
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char password[5] = "1234";
char tempPassword[5];
int tempPasswordIndex = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
char key = keypad.getKey();
if (key){
tempPassword[tempPasswordIndex] = key;
tempPasswordIndex++;
if(tempPasswordIndex>4)
{
tempPasswordIndex = 0;
if(checkPassword())
{
Serial.println("Password corretta");
}
else
{
Serial.println("Password errata");
}
}
}
delay(250);
}
boolean checkPassword()
{
if(strncmp(password, tempPassword, 4) == 0)
{
return true;
}
return false;
}






