#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Définition des broches pour le clavier matriciel
const byte ROWS = 4; // Quatre lignes
const byte COLS = 3; // Quatre colonnes
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {2, 17, 4, 5}; // Connecter aux broches GPIO
byte colPins[COLS] = {19, 0, 18};
// Initialiser l'écran LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Bonjour");
// Initialiser les broches du clavier
for (int i = 0; i < ROWS; i++) {
pinMode(rowPins[i], OUTPUT);
}
for (int i = 0; i < COLS; i++) {
pinMode(colPins[i], INPUT_PULLUP);
}
}
void loop() {
for (int row = 0; row < ROWS; row++) {
digitalWrite(rowPins[row], LOW);
for (int col = 0; col < COLS; col++) {
if (digitalRead(colPins[col]) == LOW) { // Si une touche est pressée
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(keys[row][col]); // Affiche la touche pressée
delay(500); // Petite pause pour éviter le rebond
while (digitalRead(colPins[col]) == LOW); // Attendre que la touche soit relâchée
}
}
digitalWrite(rowPins[row], HIGH);
}
}