I am trying to display two menu type in 16x2 LCD display using keypad in Arduino.
Here is the code; `#include <Wire.h> #include <LiquidCrystal_I2C.h> #include <Keypad.h>
byte rowPins[4]={9,8,7,6};
byte colPins [4]={5,4,3,2};
char keys[4][4]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,4,4);
LiquidCrystal_I2C lcd(0x27,16,2);
boolean present = false;
boolean next = false;
boolean final = false;
String num1, num2; //
float ans;//
char op;//
//String Line1 = " ";
//String Line2 = " ";
//char cursors = 0;
//
////phaseshift
//char phase_value[2];
//int phase_cursor;
//int phase_index;
//char phasesign;
//
////declare function
//void Phaseshift_Fn();
//void CV_Fn();
//void CC_Fn();
//void Remote_Fn();
void setup() {
lcd.init();
lcd.backlight();
lcd.begin (16,2);
lcd.clear();
lcd.setCursor(0, 0); lcd.print(Line1);
lcd.setCursor(0, 1); lcd.print(Line2);
delay(100);
lcd.setCursor(5,0);
lcd.print("HELLO");
lcd.setCursor(0,1);
lcd.print("PRESS FWD Button");
delay(2000);
lcd.clear();
delay(1000);
}
void loop() {
char key = keypad.getKey();
if(key == 'B'){
lcd.setCursor(0,0);
lcd.print("IF NO AIR BUBBLE");
lcd.setCursor(0,1);
lcd.print("PRESS STOP");
}
if(key == 'A'){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("PRESS MODE");
lcd.setCursor(0,1);
switch(mode)
{
case Startup:
lcd.begin(16,2);
lcd.clear();
lcd.setCursor(0,0);
Line1 = "Enter Amount";
lcd.print(Line1);
lcd.setCursor(0,1);
Line2 = "Enter Time";
lcd.print(Line2);
delay(1000);
mode = Mainmenu;
break;
}
if (key != NO_KEY && (key=='1'||key=='2'||key=='3'||key=='4'||key=='5'||key=='6'||key=='7'||key=='8'||key=='9'||key=='0'))
{
if (present != true)
{
num1 = num1 + key; // storing the value of key pressed in num1
float numLength = num1.length();
lcd.setCursor(0, 1); /* decaling the place where the first entry will be displayed*/
lcd.print(num1); // printing the first number entered
}
else
{
num2 = num2 + key;//storing the value of second key pressed in num2
float numLength = num2.length();
lcd.setCursor(4, 1);/*decaling the place where the second entry will be displayed*/
lcd.print(num2); //printing the second number entered
final = true;
}
}
}`
As a beginner of the Arduino programming I tried so many methods including switch methods also. But it didn't display. Please anyone can help me to solve this code?
I am trying to display this;enter image description here
Here I want to display when I click the S button there two menus are displaying. They are Stop and Start. I want to display that two in LCD and if start button click then machine is forward after that when I click the stop button it should be stopped.