// Bibliothèques nécessaires #include #include // Initialisation de l'écran LCD (adresse 0x27, 16 colonnes, 2 lignes) LiquidCrystal_I2C ecran(0x27, 16, 2); // Constantes const int brocheBouton = 2; // Bouton poussoir const int brocheLED = 3; // LED // Caractères utilisables const char majuscules[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const char minuscules[] = "abcdefghijklmnopqrstuvwxyz"; const char chiffres[] = "0123456789"; const char speciaux[] = "!@.?"; void setup() { pinMode(brocheBouton, INPUT_PULLUP); pinMode(brocheLED, OUTPUT); // Initialisation de l'écran ecran.begin(16, 2); ecran.backlight(); ecran.setCursor(0, 0); ecran.print("Demarrage..."); digitalWrite(brocheLED, HIGH); // LED allumée au démarrage delay(1000); digitalWrite(brocheLED, LOW); ecran.clear(); ecran.print("Pret."); } String genererMotDePasse() { char motDePasse[13]; // 12 caractères + fin de chaîne motDePasse[0] = majuscules[random(strlen(majuscules))]; motDePasse[1] = minuscules[random(strlen(minuscules))]; motDePasse[2] = chiffres[random(strlen(chiffres))]; motDePasse[3] = speciaux[random(strlen(speciaux))]; for (int i = 4; i < 12; i++) { int ensemble = random(4); switch (ensemble) { case 0: motDePasse[i] = majuscules[random(strlen(majuscules))]; break; case 1: motDePasse[i] = minuscules[random(strlen(minuscules))]; break; case 2: motDePasse[i] = chiffres[random(strlen(chiffres))]; break; case 3: motDePasse[i] = speciaux[random(strlen(speciaux))]; break; } } motDePasse[12] = '\0'; return String(motDePasse); } void loop() { if (digitalRead(brocheBouton) == LOW) { digitalWrite(brocheLED, HIGH); delay(200); digitalWrite(brocheLED, LOW); String mdp = genererMotDePasse(); ecran.clear(); ecran.setCursor(0, 0); ecran.print("Mot de passe:"); ecran.setCursor(0, 1); ecran.print(mdp); delay(2000); // Attente avant d'accepter une nouvelle génération } }