Program code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3, POSITIVE); // Set the LCD I2C address
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','4','7','*'},
{'2','5','8','0'},
{'3','6','9','#'},
{'A','B','C','D'}
};
byte rowPins[ROWS] = {3, 2, 8, 0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
lcd.begin(20,4);
Serial.begin(9600);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Select Your Language");
lcd.setCursor(0,1);
lcd.print("[1]English");
lcd.setCursor(0,2);
lcd.print("[2]Italian");
lcd.setCursor(0,3);
lcd.print("[3]Chinese");
}
void loop(){
char customKey = customKeypad.getKey();
language();
}
void language()
{
char customKey = customKeypad.getKey();
switch (customKey)
{
case '1':
lcd.clear();
lcd.setCursor(0,0);
lcd.print("English");
lcd.setCursor(0,1);
lcd.print("[1]Name");
lcd.setCursor(0,2);
lcd.print("[2]Age");
switch (customKey)
{
case '1':
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Your Name is Jack");
break;
case '2':
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Your Age is 29");
break;
}
break;
case '2':
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Italain");
lcd.setCursor(0,1);
lcd.print("[1]Nome");
lcd.setCursor(0,2);
lcd.print("[2]Età");
break;
}
}
when i run my this program code
first it showing like this
Select Your Language
[1]English
[2]Italian
[3]Chinese
when I press [1]
it show
Your Name is Jack
but actually i want it display
English
[1]Name
[2]Age
at the same time though the "Your Name is Jack"
im presser switch [2] it going to Italian
so the switch case that i use it not properly right. that make it switch case are only can be use once time only. I wanna to make sure that using the switch case, it can be use many with difference instruction.