Bonjour à tous,
je vais essayer d'être clair... J'ai un clavier 4x4...
j'ai créer un programme qui lorsque je rentre mon code et que je valide par la lettre A sur le clavier actionne un servo moteur et affiche des choses sur un écran LCD.
Cependant, je voudrais que la validation ne se fasse pas en appuyant sur le "A" du clavier 4x4 mais en appuyant sur un bouton poussoir externe... Toutes mes tentatives ont été vouées à l'échec...
dans le programme ci-joint j'ai ajouter un bouton poussoir en mode PULLUP sur la pin A4:
int pinBoutonValider = A4;
pinMode(pinBoutonValider, INPUT_PULLUP);
j'ai fais des test du type if(!BoutonValider)....
rien ne marche....
Si quelqu'un peut m'aider ?
Merci d'avance
#include <Password.h> //http://playground.arduino.cc/uploads/Code/Password.zip use password library
#include <Keypad.h> //http://www.arduino.cc/playground/uploads/Code/Keypad.zip //tells to use keypad library
#include <Servo.h> //tells to use servo library
#include <LiquidCrystal.h>
LiquidCrystal monEcran(12, 11, A3, A2, A1, A0);
Servo myservo; //declares servo
Password password = Password("2580"); //password to unlock box, can be changed
const byte ROWS = 4; // Four rows
const byte COLS = 4; // columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 8, 7, 6, 9 };// quand on regarde le clavier de face, connection la plus a gauche =8 puis 7,6,,9
byte colPins[COLS] = { 5, 4, 3, 2 };//quand on regarde le clavier de face, la 5eme connection du clavier = 5 puis 4... et la derniere =2
int pinBoutonValider, pinBoutonAnnuler;
boolean BoutonValider = 1;
boolean BoutonAnnuler = 1;
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
pinBoutonValider = A4;
pinBoutonAnnuler = 10;
pinMode(pinBoutonValider, INPUT_PULLUP);
pinMode(pinBoutonAnnuler, INPUT_PULLUP);
Serial.begin(9600);
Serial.write(254);
Serial.write(0x01);
delay(200);
//pinMode(11, OUTPUT); //green light
//pinMode(12, OUTPUT); //red light
myservo.attach(13); //servo on digital pin 9 //servo
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
myservo.write(170);
monEcran.begin(16, 2); //on initialise la communication avec 16 colonnes et deux lignes
monEcran.clear(); // on efface l'écran
monEcran.print("Hello Geocacheur");
monEcran.setCursor(0, 1);
monEcran.print("Entrez le code");
delay(3000);
monEcran.clear(); // on efface l'écran
monEcran.setCursor(0, 0);
monEcran.print("Code :");
monEcran.setCursor(0, 1);
}
void loop() {
// monEcran.print("Entrez votre code");
keypad.getKey();
}
//take care of some special events
void keypadEvent(KeypadEvent eKey) {
myservo.write(170);
switch (keypad.getState()) {
case PRESSED:
Serial.print("Enter: ");
Serial.println(eKey);
delay(10);
monEcran.print(eKey);
Serial.write(254);
switch (eKey) {
case 'A': checkPassword(); delay(1); break;
case 'B': ResetPassword(); delay(1); break;
default: password.append(eKey); delay(1);
}
}
}
void checkPassword() {
Serial.println("GO");
if (password.evaluate()) { //if password is right open box
Serial.println("Accepted");
Serial.write(254); delay(10);
//Add code to run if it works
// digitalWrite(11, HIGH);//turn on
//wait 5 seconds
// digitalWrite(11, LOW);// turn off
monEcran.clear();
monEcran.print("Code Accepte");
delay(500);
monEcran.clear(); // on efface l'écran
monEcran.setCursor(0, 0);
monEcran.print("Bravo !!!");
monEcran.setCursor(0, 1);
monEcran.print("Cache Ouverte");
password.reset();
myservo.write(15); //160deg
delay(500);
delay(2000);
//myservo.write(175);
} else {
Serial.println("Denied"); //if passwords wrong keep box locked
Serial.write(254); delay(10);
//add code to run if it did not work
// myservo.write(15);
// digitalWrite(12, HIGH); //turn on
delay(500); //wait 5 seconds
// digitalWrite(12, LOW);//turn off
monEcran.clear();
monEcran.print("Code FAUX");
delay(2000);
monEcran.clear(); // on efface l'écran
monEcran.setCursor(0, 0);
monEcran.print("Code :");
monEcran.setCursor(0, 1);
password.reset();
}
}
void ResetPassword() {
monEcran.clear();
monEcran.setCursor(0, 0);
monEcran.print("Code :");
monEcran.setCursor(0, 1);
password.reset();
}
keypad_password_servo_seb_v2.ino.ino (4.65 KB)