#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
#include <Servo.h>
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
#define Password_Length 5 // Inserire la lunghezza della password
//se la password è lunga 7 caratteri inserire 8
//se la password è lunga 8 caratteri inserire 9 ecc..
char Password[Password_Length];
char data[Password_Length];
byte data_count = 0, master_count = 0;
char customKey;
char ckPassword[Password_Length];
char pippo;
const int rgbPins[] = { 13, 12, 11};
unsigned long inizio, fine, trascorso; // variabili per funzioni millis() showStartupMessage
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
void setup() {
Serial.begin(9600);
myservo.attach(10); // attaches the servo on pin 10 to the servo object
//myservo.write(pos + 180);
for ( int i = 0; i < 3; i++)
pinMode( rgbPins[i], OUTPUT); // inizializziamo le uscite arduino -> RGB come uscite
digitalWrite(rgbPins[0], HIGH);
lcd.init(); // initialize the lcd
showStartupMessage();
lock();
}
void loop() {
lcd.setCursor(0, 0);
lcd.print("premi un tasto");
lcd.setCursor(0, 1);
lcd.print("per iniziare");
lcd.setCursor(0, 2);
lcd.print("premi B per chiudere");
//REDlcdBlynk();
customKey = keypad.waitForKey();
if (customKey == '#') {
changePw();
}
else if (customKey == 'B') {
lock ();
}
else if ( customKey ) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("PASSWORD?:");
for (data_count; data_count < Password_Length - 1; data_count++) {
customKey = keypad.waitForKey();
data[data_count] = customKey;
lcd.setCursor(data_count, 2);
lcd.print('*');//stampa * al posto del carattere che hai digitato
//lcd.print(data[data_count]); //se vuoi stampare cosa stai digitando
Serial.println(data);
}
char pippo[Password_Length];
EEPROM.get(0, pippo);
//Serial.println ("controllo");
//Serial.println(pippo);
//Serial.println(ckPassword);
//delay(1000);
if (strcmp(pippo, data) == 0) {
//GREENlcdBlynk();
lcd.setCursor(0, 3);
lcd.print(" Pass Corretta");
delay(500);
lcd.clear();
clearData();
unlock ();
}
else if (strcmp(pippo, data) != 0) {
REDlcdBlynk();
lcd.setCursor(0, 3);
lcd.print("Pass Errata");
delay(500);
Serial.println("44444");
lcd.clear();
clearData();
}
}
lcd.clear();
clearData();
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
keypad:R1
keypad:R2
keypad:R3
keypad:R4
keypad:C1
keypad:C2
keypad:C3
keypad:C4
lcd1:GND
lcd1:VCC
lcd1:SDA
lcd1:SCL
rgb1:R
rgb1:COM
rgb1:G
rgb1:B
r1:1
r1:2
r2:1
r2:2
r3:1
r3:2
servo1:GND
servo1:V+
servo1:PWM