-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcajaFuerte.ino
240 lines (216 loc) · 5.85 KB
/
cajaFuerte.ino
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
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//int buzzer = 50;
// Inicializamos el sensor DHT11
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
#include <Servo.h>
#include <Keypad.h>
//Variables
int mot_min = 150; //min servo angle (set yours)
int mot_max = 60; //Max servo angle (set yours)
int character = 0;
int activated =0;
int intentos = 3;
char Str[16] = {' ', ' ', ' ', ' ', ' ', ' ', '-', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', ' '};
//Pins
Servo myservo;
int buzzer=50; //pin for the buzzer beep
//int external = 12; //pin to inside open
//int internal = 13; //pin to inside close
//Keypad config
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','4','7','*'},
{'2','5','8','0'},
{'3','6','9','#'},
{'A','B','C','D'}
};
byte rowPins[ROWS] = {6, 7, 8, 9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {2, 3, 4, 5}; //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(){
myservo.attach(48); //attach the servo to pin D10
pinMode(buzzer,OUTPUT);
Serial.begin(9600);
// pinMode(external,INPUT);
// pinMode(internal,INPUT);
//Init the screen and print the first text
lcd.begin(16, 2);
lcd.backlight();
lcd.clear();
lcd.print(" PIN:");
lcd.setCursor(0,1);
lcd.print(" -*** ");
//put the servo in the close position first
myservo.write(mot_min);
}
void loop(){
///////////////KEYPAD OPEN/CLOSE////////////
char customKey = customKeypad.getKey(); //this function reads the presed key
if (customKey){
if (character ==0)
{
Serial.println(customKey);
Str[6]= customKey;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" PIN:");
lcd.setCursor(0,1);
lcd.print(Str);
digitalWrite(buzzer,HIGH);
delay(100);
digitalWrite(buzzer,LOW);
}
if (character ==1)
{
Serial.println(customKey);
Str[7]= customKey;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" PIN:");
lcd.setCursor(0,1);
lcd.print(Str);
digitalWrite(buzzer,HIGH);
delay(100);
digitalWrite(buzzer,LOW);
}
if (character ==2)
{
Serial.println(customKey);
Str[8]= customKey;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" PIN:");
lcd.setCursor(0,1);
lcd.print(Str);
digitalWrite(buzzer,HIGH);
delay(100);
digitalWrite(buzzer,LOW);
}
if (character ==3)
{
Serial.println(customKey);
Str[9]= customKey;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" PIN:");
lcd.setCursor(0,1);
lcd.print(Str);
digitalWrite(buzzer,HIGH);
delay(100);
digitalWrite(buzzer,LOW);
}
if (character >=4)
{
Serial.println(customKey);
digitalWrite(buzzer,HIGH);
delay(100);
digitalWrite(buzzer,LOW);
if(customKey == 'A'){
activated=1;
}
}
character=character+1;
}
if (activated == 1)
{
/*Change your password below!!!
Change each of Str[6], Str[7], Str[8], Str[9]*/
if( Str[6]=='3' && Str[7]=='0' && Str[8]=='0' && Str[9]=='7' )
{
myservo.write(mot_max);
lcd.clear();
lcd.setCursor(4,0);
lcd.print("ACCEPTED");
activated = 2;
digitalWrite(buzzer,HIGH);
delay(250);
digitalWrite(buzzer,LOW);
delay(250);
digitalWrite(buzzer,HIGH);
delay(250);
digitalWrite(buzzer,LOW);
lcd.clear();
lcd.setCursor(4,0);
lcd.print("Bienvenido");
delay(500);
delay(1000);
lcd.clear();
lcd.setCursor(1,0);
lcd.print("PUERTA ABIERTA");
}
else
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("PIN INCORRECTO");
lcd.setCursor(3,1);
lcd.print("INTENTOS: ");
lcd.print(intentos-1);
digitalWrite(buzzer,HIGH);
delay(1200);
digitalWrite(buzzer,LOW);
character=0;
Str[6]= '-';
Str[7]= '*';
Str[8]= '*';
Str[9]= '*';
Str[10]= ' ';
activated = 0;
lcd.clear();
lcd.setCursor(4,0);
lcd.print(" PIN:");
lcd.setCursor(0,1);
lcd.print(Str);
intentos=intentos-1;
}
if(intentos==0){
int segundostotal =30;
int aminutos;
int asegundos;
while(segundostotal>0){
lcd.clear();
lcd.setCursor(1,0);
lcd.print("CAJA BLOQUEADA");
lcd.setCursor(0,1);
lcd.print("INTENTE EN ");
segundostotal--;
aminutos = (segundostotal / 60) % 60;
asegundos = segundostotal % 60;
if (aminutos < 10) lcd.print("0"); // Si los minutos son menor que 10, pone un "0" delante.
lcd.print(aminutos);
lcd.print(":");
if (asegundos < 10) lcd.print("0"); // si el valor de segundo esta por debajo de 9 (unidad) antepone un cero
lcd.print(asegundos);
delay (1000);
}
intentos=3;
}
}
if (activated == 2)
{
if(customKey == 'C' )
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("PUERTA CERRADA");
delay(2000);
myservo.write(mot_min);
activated = 0;
character=0;
Str[6]= '-';
Str[7]= '*';
Str[8]= '*';
Str[9]= '*';
Str[10]= ' ';
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" PIN:");
lcd.setCursor(0,1);
lcd.print(Str);
}
}
}