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
|
//initialisation du clavier
#include <Keypad.h> //include keypad library - first you must install library (library link in the video description)
//initialisation du LCD I2C
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
#define redLED 10 //define the LED pins
#define blueLED 11
char* password ;
int i;
const byte rows = 4; //number of the keypad's rows and columns
const byte cols = 4;
char keyMap [rows] [cols] = { //define the cymbols on the buttons of the keypad
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins [rows] = {13, 12, 11, 10}; //pins of the keypad
byte colPins [cols] = {9, 8, 7, 6};
Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols);
// On définit le type crypto
struct t_crypto {
const char* ID;
const char* Red;
const char* Blue;
};
t_crypto Code[] = {
{"A1C2", "8AA4", "7C9A" },
{"C312", "651A", "8A52"},
{"AA98", "74A1", "8C8A"},
{"7A54", "A35C", "55C2"},
{"3A3C", "3A3C", "01A5"},
{"3C5A", "AAAA", "80C4"},
{"648C", "CC1C", "92C1"},
{"9761", "C7A4", "3333"}
};
void choisirCarteAleatoire()
{
long carteCrypto = random(0, 8);
Serial.println(carteCrypto);
Serial.println(F("Crypto carte: "));
Serial.println(Code[carteCrypto].ID);
Serial.println(Code[carteCrypto].Red);
Serial.println(Code[carteCrypto].Blue);
password = Code[carteCrypto].Red;
Serial.print(password);
}
void setup () {
Serial.begin(115200);
// Pour activer l'état HOLD
unsigned int time_hold = 4;
//Ecran
lcd.init();
// Print a message to the LCD.
lcd.backlight();
pinMode(redLED, OUTPUT); //set the LED as an output
pinMode(blueLED, OUTPUT);
randomSeed(analogRead(A0)); // génération d'un peu d'aléatoire
choisirCarteAleatoire();
}
void loop () {
int taille_code = 4;
char code_secret[taille_code] = {password}; //tableau contenant code
char code_tape[taille_code] = {0}; //tableau contenant la saie
for ( i = 0 ; i < taille_code; ) {
char whichKey = myKeypad.getKey(); //define which key is pressed with getKey
if (whichKey) {
code_tape[i] = whichKey;
Serial.print("*");
Serial.println(code_tape[i]);
i++;
}
if (i == 4) {
Serial.println(code_tape);
Serial.println(password);
if (code_tape == password) {
Serial.print("accès accordé");
} else {
Serial.print("code erreur");
}
}
}
} |
Partager