Codice

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <Keypad.h>
#include "font.h";
// keypad configuration
const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[rows] = {8, 7, 6, 5};
byte colPins[cols] = {4, 3, 2};
char psw[7] = "010315";// PASSWORD
char inputCode[7];// CODICE INSERIMENTO
int rele = 13;// USCITA PER ATTIVARE IL RELE'
int buzz = 11;
int inputCode_idx;//CONTATORE PER DODICE INSERITO
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
void setup(){
Serial.begin(9600);
keypad.setDebounceTime(150);
pinMode(rele,OUTPUT);
pinMode(buzz,OUTPUT);
inputCode_idx = 0;// RESETTA IL CONTATORE DEL CODICE
}
void loop(){
char key = keypad.getKey();
//Serial.println(psw[1]);
if(key !=NO_KEY){
if(key== '#'){
inputCode_idx = 0;// RESETTA IL CODICE
Serial.println("CODICE RESETTATO");
delay(1000);
}else{
inputCode[inputCode_idx++] = key;
Serial.print(key);
if(inputCode_idx == 6){
inputCode[inputCode_idx] = '\0';
inputCode_idx = 0;
Serial.println();
Serial.println(inputCode);
if(strcmp(inputCode,psw) != 0){
digitalWrite(buzz,HIGH);
delay(1000);
digitalWrite(buzz,LOW);
}
}
}
}
if(strcmp(inputCode,psw) == 0){
digitalWrite(rele,HIGH);
Serial.println("APERTO");
delay(2000);
Serial.println("CHIUSO");
for(int i=0;i<6;i++){
inputCode[i] = '\0';
}
66
}
67
68
69
digitalWrite(rele,LOW);
70
71 }