#include <Wire.h>
#include <Keypad.h>
#include <LiquidCrystal.h>
// Keypad declaration
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
// Lcd declaration
const int rs = 37, en = 36, d4 = 35, d5 = 34, d6 = 33, d7 = 32;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// Relais declaration
const int Poste_1 = 22; // const int (ne peut pas etre modifie pendant l'execution du programme et prends moind de place en mémoire)
const int Poste_2 = 23 ;
const int Poste_3 = 24 ;
const int Poste_4 = 25 ;
const int Poste_5 = 26 ;
const int Poste_6 = 27 ;
const int Poste_7 = 28 ;
const int Poste_8 = 29 ;
void setup(){
// Initialisation Lcd
lcd.begin(16,2);
lcd.setCursor(1, 0); // Lcd.setCursor permet de choisir la ligne et la colonne ou va apparaitre le texte
lcd.print("Centre de paie");
lcd.setCursor(6, 2);
lcd.print("ISK");
delay(1000);
lcd.clear(); // Effacer l'ecran
lcd.print("Choisir un poste");
lcd.setCursor(0, 2);
lcd.blink(); // Curseur clignotant
// Initialisation des relais
pinMode(22, OUTPUT);
pinMode(23, OUTPUT);
pinMode(24, OUTPUT);
pinMode(25, OUTPUT);
pinMode(26, OUTPUT);
pinMode(27, OUTPUT);
pinMode(28, OUTPUT);
pinMode(29, OUTPUT);
// Etat des relais à l'initialisation
digitalWrite(22, LOW);
digitalWrite(23, LOW);
digitalWrite(24, LOW);
digitalWrite(25, LOW);
digitalWrite(26, LOW);
digitalWrite(27, LOW);
digitalWrite(28, LOW);
digitalWrite(29, LOW);
// lcd.noDisplay();
// delay(900);
// lcd.display();
//delay(5000);
}
void loop(){
int customKey = customKeypad.getKey();
int tempsdejeu = customKey;
if (customKey){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(customKey);
}
switch (customKey){
case '1' :
lcd.setCursor(2, 2);
lcd.setCursor(0, 0);
delay(2000);
lcd.clear();
lcd.print("Combien de temps ?");
lcd.setCursor(0, 2);
lcd.blink();
delay(3000);
tempsdejeu = customKey;
digitalWrite(22, HIGH);
lcd.clear();
lcd.print("Poste 1 allume");
delay(3000);
delay(tempsdejeu);
digitalWrite(22,LOW);
lcd.clear();
// Fin du choix
lcd.print("Choisir un poste");
lcd.setCursor(0, 2);
lcd.blink();
break;
lcd.print("Choisir un poste");
case '2' :
lcd.setCursor(2, 2);
lcd.setCursor(0, 0);
delay(2000);
lcd.clear();
digitalWrite(23, HIGH);
lcd.print("Poste 2 allume");
delay(3000);
lcd.clear();
// Fin du choix
lcd.print("Choisir un poste");
lcd.setCursor(0, 2);
lcd.blink();
break;
case '3' :
lcd.setCursor(2, 2);
lcd.setCursor(0, 0);
delay(2000);
lcd.clear();
digitalWrite(24, HIGH);
lcd.print("Poste 3 allume");
delay(3000);
lcd.clear();
// Fin du choix
lcd.print("Choisir un poste");
lcd.setCursor(0, 2);
lcd.blink();
break;
}
}