Bonjour !
J'ai ce code mais ça ne marche qu'une fois sur deux, est-ce qu'il y a un problème avec le reste automatique ? Pouvez-vous m'aider ?
Merci !
#include <Password.h> //http://playground.arduino.cc/uploads/Code/Password.zip //tells to use password library
#include <Keypad.h> //http://www.arduino.cc/playground/uploads/Code/Keypad.zip //tells to use keypad library
Password password = Password( "1234" ); //password to unlock, can be changed
const byte ROWS = 4; // Four rows
const byte COLS = 3; // columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 9, 8, 7, 6 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 5, 4, 3 };
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
Serial.write(254);
Serial.write(0x01);
delay(200);
pinMode(11, OUTPUT); //green light
pinMode(12, OUTPUT); //red light
pinMode(13, OUTPUT); // electro
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}
void loop(){
digitalWrite(13, HIGH);
keypad.getKey();
}
//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
Serial.print("Enter:");
Serial.println(eKey);
delay(10);
switch (eKey){
case '*': checkPassword(); delay(1); break;
case '#': password.reset(); delay(1); break;
default: password.append(eKey); delay(1);
;
}
}
}
void checkPassword(){
if (password.evaluate()){ //if password is right open
Serial.println("Accepted");
digitalWrite(13, LOW);//Désarme l'electro-aimant
digitalWrite(11, HIGH);//allume led verte
delay(2000); //Temps qui peut être changé
digitalWrite(11, LOW);// éteint led verte
}else{
Serial.println("Denied"); //if passwords wrong keep locked
delay(1000); //
password.reset(); // faire une mise à zéro et attends mot de passe
digitalWrite(12, HIGH); //led rouge allumée
delay(2000); //wait 5 seconds
digitalWrite(12, LOW);//led rouge éteinte
}
}