-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4x4 keypad(password).txt
253 lines (195 loc) · 6.97 KB
/
4x4 keypad(password).txt
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
*############################## KEYPAD INPUT ##################################
This sketch takes input from a keypad and displays the key that was
pressed on an LCD screen.
To read the keypad input that is is a 4x4 input, we are using a
library from the arduino website called Keypad. You can download this
library at: http://arduino.cc/playground/Code/Keypad
From: Mike Myers (http://mikemyers.me) @netnutmike
Let's Make It Episode 6 (http://tech-zen.tv/index.php/shows/let-s-make-it/episodes/59-sensor-fun-with-arduino-1-massive-failure-but-4-successes-let-s-make-it-episode-6)
http://tech-zen.tv
For the sample code, show notes, contact information and many more
videos, visit the show page at http://tech-zen.tv/letsmakeit
Please subscribe to our YouTube channel or our netcasts at any of
your favorite netcast / podcast outlets.
We normally record Let's Make It live on Tuesday evenings around
7pm eastern. You can watch it live by going to tech-zen.tv and clicking
the live link at the top of the page.
We also have a community setup for our viewers and listeners. You can
join the community by going to community.tech-zen.tv.
We love input on what you would like to know or if you have an idea for
a new Let's Make it episode, you can contact us via email or phone at
the show information page.
################################################################################*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
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] = {11,10,9,8};
byte colPins[cols] = {7,6,5,4};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
LiquidCrystal_I2C lcd(0x3F,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("You Pressed:");
}
void loop()
{
char key = keypad.getKey();
if (int(key) != 0) {
lcd.setCursor(16,0);
lcd.print(key);
}
}
Passcode Entry
/*############################## SECRET KEYCODE ##################################
This sketch takes input from a keypad for s secret code. If the code is
entered correctly it turns on a green LED to simulate access granted and
displays on the LCD access granted.
If an invalid code is entered, the red LED is lit and access denied is
displayed on the LCD.
To read the keypad input that is is a 4x4 input, we are using a
library from the arduino website called Keypad. You can download this
library at: http://arduino.cc/playground/Code/Keypad
From: Mike Myers (http://mikemyers.me) @netnutmike
Let's Make It Episode 6 (http://tech-zen.tv/index.php/shows/let-s-make-it/episodes/59-sensor-fun-with-arduino-1-massive-failure-but-4-successes-let-s-make-it-episode-6)
http://tech-zen.tv
For the sample code, show notes, contact information and many more
videos, visit the show page at http://tech-zen.tv/letsmakeit
Please subscribe to our YouTube channel or our netcasts at any of
your favorite netcast / podcast outlets.
We normally record Let's Make It live on Tuesday evenings around
7pm eastern. You can watch it live by going to tech-zen.tv and clicking
the live link at the top of the page.
We also have a community setup for our viewers and listeners. You can
join the community by going to community.tech-zen.tv.
We love input on what you would like to know or if you have an idea for
a new Let's Make it episode, you can contact us via email or phone at
the show information page.
################################################################################*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
//constants for LEDs
int greenLED = 12;
int redLED = 13;
//set our code
char* ourCode = "1234";
int currentPosition = 0;
//define the keypad
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] = {11,10,9,8};
byte colPins[cols] = {7,6,5,4};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
LiquidCrystal_I2C lcd(0x3F,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
//lcd.init();
// Print a message to the LCD.
lcd.backlight();
displayCodeEntryScreen();
//setup and turn off both LEDs
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, LOW);
}
void loop()
{
int l;
char key = keypad.getKey();
if (int(key) != 0) {
lcd.setCursor(14,3);
lcd.print(" ");
lcd.setCursor(14,3);
for (l=0; l<=currentPosition; ++l)
{
lcd.print("*");
}
if (key == ourCode[currentPosition])
{
++currentPosition;
if (currentPosition == 4)
{
unlockDoor();
currentPosition = 0;
}
} else {
invalidCode();
currentPosition = 0;
}
}
}
void invalidCode()
{
digitalWrite(redLED, HIGH);
clearScreen();
lcd.setCursor(0,0);
lcd.print("********************");
lcd.setCursor(0,1);
lcd.print("** ACCESS DENIED! **");
lcd.setCursor(0,2);
lcd.print("** INVALID CODE **");
lcd.setCursor(0,3);
lcd.print("********************");
delay(5000);
digitalWrite(redLED, LOW);
displayCodeEntryScreen();
}
void unlockDoor()
{
digitalWrite(greenLED, HIGH);
clearScreen();
lcd.setCursor(0,0);
lcd.print("********************");
lcd.setCursor(0,1);
lcd.print("** ACCESS GRANTED **");
lcd.setCursor(0,2);
lcd.print("** WELCOME!! **");
lcd.setCursor(0,3);
lcd.print("********************");
//add any code to unlock the door here
delay(5000);
digitalWrite(greenLED, LOW);
displayCodeEntryScreen();
}
void displayCodeEntryScreen()
{
clearScreen();
lcd.setCursor(0,0);
lcd.print("Let's Make It Secret");
lcd.setCursor(0,1);
lcd.print("Code Project...");
lcd.setCursor(0,2);
lcd.print("Enter Secret Code:");
}
void clearScreen()
{
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,2);
lcd.print(" ");
lcd.setCursor(0,3);
lcd.print(" ");
}