Ciao,
Quando avvio il mio programma dovrebbe fare in modo che ti faccia inserire la prima volta la password che sarà giusta, mentre le altre volte ti farà inserire la password e il programma capisce se è giusto o no ma mi si refresha lcd e riparte tutto da capo quando devo inserire la seconda password.
Questo è il codice:
#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
int ledPin = 5; // LED on Pin 13 of Arduino
int pirPin = 4; // Input for HC-S501
int pirValue; // Place to store read PIR Value
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
int i=11, g=0;
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {7, 6, A1, A0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A2, A3, A4, A5}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print("Inserisci la ");
lcd.setCursor(0,2);
lcd.print("Password:");
lcd.setCursor(10,2);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
digitalWrite(ledPin, LOW);
}
void loop() {
char key = customKeypad.getKey(), temp[3], temp2[3];
int j, uscita;
pirValue = digitalRead(pirPin);
if(pirValue==HIGH){
digitalWrite(ledPin, HIGH);
}
if(g<4){
if (key){
temp[g]=key;
lcd.print(key);
lcd.setCursor (i++, 2);
g++;
}
if(i==15){
delay(500);
lcd.clear();
i=11;
lcd.setCursor(0,0);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
lcd.print("Password");
lcd.setCursor(0,2);
lcd.print("Impostata");
delay(2000);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Inserisci la ");
lcd.setCursor(0,2);
lcd.print("Password:");
lcd.setCursor(10,2);
}
}
if(g>3 && g<8){
do{
key = customKeypad.getKey();
if(key){
temp2[g]=key;
lcd.print(key);
lcd.setCursor(i++, 2);
g++;
}
if(i==14){
for(j=0; j<4; j++){
if(temp2[j]==temp[j]){
}
else{
digitalWrite(2, HIGH);
lcd.setCursor(10,2);
lcd.print(' ');
lcd.setCursor(11,2);
lcd.print(' ');
lcd.setCursor(12,2);
lcd.print(' ');
lcd.setCursor(13,2);
lcd.print(' ');
i=11;
lcd.setCursor(10,2);
delay(1500);
digitalWrite(2,LOW);
uscita=1;
break;
}
if(j==3){
digitalWrite(3, HIGH);
lcd.setCursor(10,2);
lcd.print(' ');
lcd.setCursor(11,2);
lcd.print(' ');
lcd.setCursor(12,2);
lcd.print(' ');
lcd.setCursor(13,2);
lcd.print(' ');
i=11;
lcd.setCursor(10,2);
delay(1500);
digitalWrite(3, LOW);
uscita=0;
break;
}
}
}
}while(uscita==1);
}
}
Mentre questo è il circuito: