Hi I am trying to use the function millis() with my lcd. What I want my code to do is display two sentences on the same line with a 3000 millis delay for each. However, I can not use the delay() function as I also have to use the keypad. With my code now when the cursor is at (0,2) the sentences keep overlapping and changing very quickly. Any suggestions on what I can add to my code to have that 3000 millis difference? Thank you.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
#include <Keypad.h>
const long interval = 3000;
unsigned long currentMillis = 3000;
const byte ROWS = 4;
const byte COLS = 4;
char keys[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 kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
long Num1,Num2,Number;
char key,action;
boolean result = false;
void setup() {
lcd.init();
lcd.begin(20,4);
lcd.backlight();
}
void loop() {
unsigned long currentMillis = millis();
lcd.setCursor(0,2);
lcd.print("Dry Bulb Temp ( C): ");
lcd.setCursor(15,2);
lcd.print((char)223);
lcd.setCursor(1,3);
lcd.print("10");
millis();
lcd.print(" ");
lcd.setCursor(0,2);
lcd.print("Wet Bulb Temp ( C): ");
lcd.setCursor(15,2);
lcd.print((char)223);
lcd.setCursor(1,3);
lcd.print("30");
millis();
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print("Enter Duct Size(in): ");
key = kpd.getKey();
if (key!=NO_KEY)
DetectButtons();
if (result==true)
CalculateResult();
DisplayResult();
}
void DetectButtons()
{
lcd.clear();
if (key=='C')
{Serial.println ("Clear"); Number=Num1=Num2=0; result=false;}
if (key == '1')
{Serial.println ("Button 1");
if (Number==0)
Number=1;
else
Number = (Number*10) + 1;
}
if (key == '4')
{Serial.println ("Button 4");
if (Number==0)
Number=4;
else
Number = (Number*10) + 4;
}
if (key == '7')
{Serial.println ("Button 7");
if (Number==0)
Number=7;
else
Number = (Number*10) + 7;
}
if (key == '0')
{Serial.println ("Button 0");
if (Number==0)
Number=0;
else
Number = (Number*10) + 0;
}
if (key == '2')
{Serial.println ("Button 2");
if (Number==0)
Number=2;
else
Number = (Number*10) + 2;
}
if (key == '5')
{Serial.println ("Button 5");
if (Number==0)
Number=5;
else
Number = (Number*10) + 5;
}
if (key == '8')
{Serial.println ("Button 8");
if (Number==0)
Number=8;
else
Number = (Number*10) + 8;
}
if (key == '#')
{Serial.println ("Equal");
Num2=Number;
result = true;
}
if (key == '3')
{Serial.println ("Button 3");
if (Number==0)
Number=3;
else
Number = (Number*10) + 3;
}
if (key == '6')
{Serial.println ("Button 6");
if (Number==0)
Number=6;
else
Number = (Number*10) + 6;
}
if (key == '9')
{Serial.println ("Button 9");
if (Number==0)
Number=9;
else
Number = (Number*10) + 9;
}
if (key == '*')
{
Num1 = Number;
Number =0;
if (key == '*')
{action = '*';}
delay(100);
}
}
void CalculateResult()
{
if (action=='*')
Number = Num1*Num2;
}
void DisplayResult()
{
lcd.setCursor(2, 1);
lcd.print(Num1); lcd.print(action); lcd.print(Num2);
if (result==true)
{lcd.print(" Area = "); lcd.print(Number/12); lcd.setCursor(17,1); lcd.print("ft");}
}