-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapstone.ino
More file actions
50 lines (42 loc) · 934 Bytes
/
capstone.ino
File metadata and controls
50 lines (42 loc) · 934 Bytes
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
#include <Keypad.h>
char* password = "123"; // change the password here, just pick any 3 numbers
int position = 0;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = { 9, 8, 7, 6 };
byte colPins[COLS] = { 5, 4, 3, 2 };
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int Lock = 13;
void setup()
{
pinMode(Lock, OUTPUT);
LockedPosition(true);
}
void loop(){
char key = keypad.getKey();
if (key == '*' || key == '#'){
position = 0;
LockedPosition(true);
}
if (key == password[position]){
position ++;
}
if (position == 3){
LockedPosition(false);
}
delay(100);
}
void LockedPosition(int locked){
if (locked){
digitalWrite(Lock, LOW);
}
else{
digitalWrite(Lock, HIGH);
}
}