-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeypad.cpp
51 lines (36 loc) · 993 Bytes
/
keypad.cpp
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
#include "keypad.h"
void Keypad::init(){
_keypad.begin();
}
bool Keypad::keyPressed(){
_keypad.tick();
while(_keypad.available()){
keypadEvent e = _keypad.read();
Serial.print((char)e.bit.KEY);
if(e.bit.EVENT == KEY_JUST_PRESSED) return true;
}
return false;
}
int Keypad::checkCode(char passwords[USERS][PASSWORD_LENGTH]){
_keypad.tick();
while(_keypad.available()){
keypadEvent e = _keypad.read();
if(millis() - lastPressed <= 1000 || e.bit.EVENT != KEY_JUST_PRESSED) continue;
_keyBuffer[_bufferSize] = e.bit.KEY;
_bufferSize++;
if(_bufferSize == PASSWORD_LENGTH - 1){
_bufferSize = 0;
for(int userId = 0; userId < USERS; userId++){
if(!strcmp(_keyBuffer, passwords[userId])) return userId; // codice corretto
}
reset();
}
}
return -1;
}
short Keypad::getBufferSize(){
return _bufferSize;
}
void Keypad::reset(){
_bufferSize = 0;
}