hello , i am working on an arduino program where i choose modes by a keypad 3x4 and display them in the LCD , i have no problem displaying the normal modes where i only use one key , but when it comes to chosing sub modes they dont show up . it only shows till the part where there is choices but when i press the keys it doesnt read it , after a certain delay it goes back to the main menu .
here is the program :
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
// Adresse I2C de l'afficheur LCD
#define I2C_ADDR 0x27 // Adresse I2C de l'écran LCD
// Dimensions du clavier 3x4
const byte ROWS = 4;
const byte COLS = 3;
// Définition des touches et de leurs modes correspondants
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; // Broches de lignes du clavier
byte colPins[COLS] = {5, 4, 3}; // Broches de colonnes du clavier
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// Création de l'objet LCD I2C
LiquidCrystal_I2C lcd(I2C_ADDR, 16, 2);
void setup() {
Wire.begin(); // Initialisation de la communication I2C
// Initialisation de l'afficheur LCD
lcd.init();
lcd.backlight(); // Allumer le rétro-éclairage
// Affichage initial
lcd.print("Machine a laver");
delay(3000);
lcd.clear();
lcd.print("Choisir le mode:");
}
void loop() {
char key = keypad.getKey();
if (key != NO_KEY) {
lcd.clear();
lcd.print("Mode choisi:");
lcd.setCursor(0, 1);
lcd.print(key);
delay(1000); // Affiche le mode choisi pendant 5 secondes
lcd.clear();
// Affichage du mode correspondant à chaque touche
switch (key) {
case '1':
lcd.print("Rapide");
// Exécutez la tâche spécifique au mode rapide ici
break;
case '2':
lcd.print("Lavage");
// Exécutez la tâche spécifique au mode lavage ici
break;
case '3':
lcd.print("Rincage");
// Exécutez la tâche spécifique au mode rincage ici
break;
case '4':
lcd.print("Essorage");
chooseSubMode("Essorage");
break;
case '5':
lcd.print("Synthetique");
chooseSubMode("Synthetique");
break;
case '6':
lcd.print("Coton");
chooseSubMode("Coton");
break;
//case '11':
// lcd.print("Retour au menu");
// delay(2000);
// lcd.clear();
// return;
// break;
default:
lcd.print("Mode inconnu");
break;
}
delay(5000); // Affiche le mode pendant 5 secondes
lcd.clear();
}
}
// Fonction pour choisir le sous-mode pour les modes spécifiques
void chooseSubMode(String mode) {
delay(1000);
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("Choisir sous");
lcd.setCursor(5 , 1);
lcd.print("mode:");
delay(3000);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("Sous mode pour ");
lcd.setCursor(3, 1);
lcd.print(mode);
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("1:Douce 2:Normale");
lcd.setCursor(3, 1);
lcd.print("3:Agressive");
char key = keypad.getKey();
if (key == NO_KEY){
}
else {
switch (key) {
case '1':
lcd.print("Douce");
// Exécutez la tâche spécifique au sous-mode douce ici
break;
case '2':
lcd.print("Normale");
// Exécutez la tâche spécifique au sous-mode normale ici
break;
case '3':
lcd.print("Agressive");
// Exécutez la tâche spécifique au sous-mode agressive ici
break;
default:
lcd.print("Mode inconnu");
break;
}
}
delay(5000); // Affiche le sous-mode pendant 5 secondes
lcd.clear();
}
any help is appreciated .