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
| #include <LiquidCrystal.h> //Inclure la librairie LCD
#include <Keypad.h> //Inclure la librairie du keypad
#define redLED 10 //Définir les LED
#define greenLED 11
char* password ="1234"; //Création du mdp
int pozisyon = 0; //Position du keypad
const byte rows = 4; //Nombre de lignes et de colonnes
const byte cols = 4;
char keyMap [rows] [cols] = { //Définir les boutons du keypad
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins [rows] = {1, 2, 3, 4};
byte colPins [cols] = {5, 6, 7, 8};
Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols);
LiquidCrystal lcd (A0, A1, A2, A3, A4, A5); // Broches du LCD. (RS, E, D4, D5, D6, D7)
void setup(){
lcd.begin(16, 2);
pinMode(redLED, OUTPUT); //Définir la LED en sortie
pinMode(greenLED, OUTPUT);
}
void loop(){
char whichKey = myKeypad.getKey();
lcd.setCursor(0, 0);
lcd.print(" Bonjour");
lcd.setCursor(0, 1);
lcd.print(" Entrez code");
if(whichKey == '*' || whichKey == '#' || whichKey == 'A' ||
whichKey == 'B' || whichKey == 'C' || whichKey == 'D'){
pozisyon=0;
setLocked (true);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Code incorrect");
delay(1000);
lcd.clear();
}
if(whichKey == password [pozisyon]){
pozisyon ++;
}
if(pozisyon == 4){
setLocked (false);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Code bon");
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Vous pouvez");
lcd.setCursor(0, 1);
lcd.print("entrer");
delay(7000);
lcd.clear();
}
delay(100);
}
void setLocked(int locked){
if(locked){
digitalWrite(redLED, HIGH);
digitalWrite(greenLED, LOW);
}
else{
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
}
} |
Partager