You are on page 1of 3

#include <LiquidCrystal_I2C.

h>
#include <Keypad.h>
#include"Servo.h"
#include"string.h"

const int L1=12,L2=11,L3=9,L4=8,C1=7,C2=6,C3=1,C4=0;


const int R=2,V=3;
const int SM=4;
const int buz=13;
const int ROW_NUM = 4; //four rows
const int COLUMN_NUM = 4; //four columns
char password[]="0411";

char keys[ROW_NUM][COLUMN_NUM] = {
{'1','2','3', 'A'},
{'4','5','6', 'B'},
{'7','8','9', 'C'},
{'*','0','#', 'D'}
};
byte pin_rows[ROW_NUM] = {L1, L2, L3, L4}; //connect to the row pinouts of the
keypad
byte pin_column[COLUMN_NUM] = {C1, C2, C3,C4}; //connect to the column pinouts of
the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM,
COLUMN_NUM );
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo S;

void setup() {
pinMode(R,OUTPUT);
pinMode(V,OUTPUT);
pinMode(buz,OUTPUT);
S.attach(SM);
lcd.init(); // initialisation de l’afficheur
lcd.backlight();
S.write(90);
lcd.clear();
lcd.print("Bonjour");
digitalWrite(V,HIGH);
delay(3000);
lcd.clear();
lcd.print("Deverrouillage");
lcd.setCursor(0,1);
lcd.print("Porte ouverte");

void loop() {
int x=0;
x=(analogRead(A0)>500);
if(x)
{
lcd.clear();
lcd.print("Verrouillage");
digitalWrite(V,LOW);
digitalWrite(R,HIGH);
S.write(0);
char U[4];
for(int t=0;t<4;t++)
U[t]='\0';
int i=0;
while(x)
{
char bp=keypad.getKey();
if(bp)
{
if(((bp>='0')&&(bp<='9'))&&(i<4))
{
tone(buz,7000,200);
U[i]=bp;
lcd.setCursor(i,1);
lcd.print("*");
/////////////////////******************************************
i++;
}
if((bp=='A')&&(i==4))
{
i=0;
lcd.clear();
lcd.print(U);
if(strcmp(password,U)==0)
{
x=0;
S.write(90);
digitalWrite(R,LOW);
digitalWrite(V,HIGH);
lcd.clear();
lcd.print("Correcte code ");
tone(buz,800);
delay(2000);
noTone(buz);
lcd.clear();
lcd.print("Dverrouillage");
//temporisateur de l'ouvertir aprés 10s
int j=9;
delay(2000);
x=(analogRead(A0)>500);
while((j>-1)&&(x==1))
{
x=(analogRead(A0)>500);
lcd.clear();
lcd.print("Verrouillage");
lcd.setCursor(0,1);
lcd.print("apres ");
lcd.setCursor(7,1);
lcd.print(j);
lcd.setCursor(9,1);
lcd.print("s");
tone(buz,800);
delay(1000);
noTone(buz);
j--;
if(j==-1)
x=0;
}

if(x==0)
{
lcd.clear();
lcd.print("Porte d'armoire");///////////
lcd.setCursor(0,1);
lcd.print("ouverte");

}
}
else
{
x=1;
for(int t=0;t<4;t++)
U[t]='\0';
int t=0;
lcd.clear();
lcd.print("Fausse code");
tone(buz,8000,1000);
delay(3000);
lcd.clear();
lcd.print("Verrouillage");
}
}

}
}

}
}

You might also like