Hi! I'm making a program wherein I will be able to switch on 3 different modes. Modes 1,2 or 3 can be obtain if keys 1,2, or 3 on the 4x3 keypad matrix is pressed.
Mode 1 = key '1' : Is the main panel wherein the LCD only displays the temperature and pH level of the water.
Mode 2 = key '2' : View log.
Mode 3 = key '3' : Enter new recipient's number.
My problem is that when I upload the sketch I can't switch to other modes and stuck at mode 1 even if I press keys 1,2 or 3. Don't know where I'm mistaken. What I want to do is that after uploading, mode 1 will be displayed first not until I hit keys 2 or 3 then it will switch modes. TIA! Here's my code:
void loop()
{
key = keypad.getKey();
//switch mode:
if (digitalRead(ledPin)==LOW)
{
//Main Panel
if (key=='1')
{
lcd.setCursor(0,0);
lcd.print("Temperature: ");
lcd.setCursor(0,1);
lcd.print("pH Level: ");
mode = 1;
}
//View log
else if (key=='2')
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("View log: ");
mode = 2;
}
//Enter new recipient's number
else if (key=='3')
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter number: ");
mode = 3;
}
else
{
lcd.setCursor(0,0);
lcd.print("Temperature: ");
lcd.setCursor(0,1);
lcd.print("pH Level: ");
mode = 1;
}
}