je reste sur ton premier code
nous sommes bien d'accord pour dire que pour allumer une led, tu dois mettre la sortie à LOW
c'est bien ça et pas l'inverse?
pour le texte, tu affiches 17 caracteres à l'écran puis tu vas lire le clavier
mais dans la boucle des 17 caracteres, tu as une tempo de 20 ms pour que tu ai le temps de lire le texte.
ce qui veut dire que tu vas lire le clavier toutes les 17*20=340ms soit 3 fois par secondes.
il faut donc rester appuyé au moins 350ms pour etre sur que la touche appuyée sera vue.
tu peux tester en raccourcissant la tempo de 20 ms
testes ce code pour la tempo de 2 secondes pour la gache
/* Arduino Security System with the Keypad and LCD
Creator Mert Kılıç - Mert Arduino Tutorial and Project
Please subscribe for support
Thanks
*/
#include <LiquidCrystal.h> //include LCD library (standard library)
#include <Keypad.h> //include keypad library - first you must install library (library link in the video description)
#define redLED 10 //define the LED pins
#define greenLED 11
char nom [] {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
'L', ' ', 'M', 'A', 'R', 'I', 'O', 'N', ' ', '4', ' ', 'R', 'u', 'e',
' ', 'M', 'a', 'c', 'h', 'i', 'n', ' ', 'T', 'r', 'u', 'c', ' ', 'C',
'h', 'o', 's', 'e',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '};
char* password = "3945"; //create a password
int pozisyon = 0; //keypad position
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] = {1, 2, 3, 4}; //pins of the keypad
byte colPins [cols] = {5, 6, 7, 8};
//byte rowPins [rows] = {A1, A2, A3, A4}; //pins of the keypad
//byte colPins [cols] = {A5, A6, A7, A8};
Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols);
LiquidCrystal lcd (A0, A1, A2, A3, A4, A5); // pins of the LCD. (RS, E, D4, D5, D6, D7)
//LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() {
Serial.begin(115200);
lcd.begin(16, 2);
pinMode(redLED, OUTPUT); //set the LED as an output
pinMode(greenLED, OUTPUT);
setLocked (true); //state of the password
}
void loop() {
lcd.setCursor(0, 1);
lcd.print(" Enter Password");
for (int f = 1; f < 50; f++) {
lcd.setCursor(0, 0);
for (int t = 1; t < 17; t++) {
lcd.write(nom[f + t]);delay(20);// Serial.println(nom[f]);
}
saisie_code();//Serial.println(nom[f]);
}
lcd.setCursor(0, 1);
lcd.print(" Enter Password");
}
void saisie_code()
{//Serial.print(password [pozisyon+1]);Serial.print("....");Serial.println(pozisyon);
char whichKey = myKeypad.getKey(); //define which key is pressed with getKey
if (whichKey == '*' || whichKey == '#' || whichKey == 'A' || //define invalid keys
whichKey == 'B' || whichKey == 'C' || whichKey == 'D') {
pozisyon = 0;//Serial.println(pozisyon);
setLocked (true); //on ferme
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Invalid Key!");
delay(1000);
lcd.clear();
}
if (whichKey == password [pozisyon]) { //si le chiffre attendu est ok, on incremente le compteur
pozisyon ++;
}
if (pozisyon == 4) { //si le compteur = 4
setLocked (false); //on ouvre
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("*** Verified ***");
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" MERCI");
lcd.setCursor(0, 1);
lcd.print("GOOD DAY");
delay(3000);
lcd.clear();
}
delay(100);
}
void setLocked(int locked) {
if (locked) { //on ferme
digitalWrite(redLED, HIGH);
digitalWrite(greenLED, LOW);
}
else { //on ouvre
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
delay(2000); //impulsion de 2 secondes sur la led/gache/solenoide
digitalWrite(redLED, HIGH);
digitalWrite(greenLED, LOW);
}
}