Salve,
ho provato a creare uno sketch (molto corto, molto semplice e molto in fretta) per verificare se un codice inserito con una keypad è esatto oppure no.
Il codice funziona, ma una volta inserito il codice, che sia corretto oppure no, questo non mi permette di digitare nuovamente altri tasti.
Lo sketch è il seguente:
#include <Wire.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
bool check=false;
int x=0;
LiquidCrystal_I2C lcd(0x27,2,3);
const byte rows = 4;
const byte cols = 3;
char keyInsert[16];
char keys[rows][cols] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[rows] = {8,9,10,11};
byte colPins[cols] = {5,6,7};
Keypad keypad = Keypad(makeKeymap(keys),
rowPins, colPins,
rows, cols);
char code[16]= "123456";
void setup()
{
Serial.begin(9600);
lcd.init();
lcd.backlight();
Wire.begin();
}
void loop()
{
pin();
}
void pin(){
char key=keypad.getKey();
if(key){
Serial.print(key);
check=(x==16);
if(key=='*' || check ) {
if(!strcmp(keyInsert,code)&& !check){
Serial.println("OK");
Serial.println(check);
} else {
Serial.println("WRONG");
Serial.println(check);
}
x=-1;
}
keyInsert[x]=key;
x++;
}
}
Kraine.