I am trying to use the LCD display to, Count up to 60 and decrease to zero, two digits only.
The up button works great and two digit mode, the problem I am having is when I use the decrease button and the account is past 10 LCD displays three digits.
The up/down Counter works from 0 to 9 excellent, but if you go past 10 and then try decreasing it jumps to three digits.
I know there is something wrong with this code, when it tries to decrease the number.
count--; // Decrement Count by 1
lcd.setCursor(0, 1);
if(10 > count);{
lcd.print("0");
}
if(count < 0) {
count = 0;
}
lcd.print(count);
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); //Assign correct Arduino digital-port
const int BUTTON1 = 8; //The pin for button1
const int BUTTON2 = 9; //The pin for button2
int count = 0;
void setup()
{
Serial.begin(9600);
pinMode(BUTTON1, INPUT);
pinMode(BUTTON2, INPUT);
lcd.begin();
lcd.clear();
// Print a message to the LCD.
lcd.print("Up-Down Counter");
// Declare Switches as INPUT to Arduino
}
void loop()
{
if(digitalRead(BUTTON1) == HIGH) // if SW1 is pressed perform action described in loop
{
count++; // Increment Count by 1
lcd.setCursor(0, 1);
if(count < 10) {
lcd.print("0");
}
if(count > 60) {
count = 60;
}
lcd.print(count);
delay(400);
}
if(digitalRead(BUTTON2) == HIGH) // if SW2 is pressed perform action described in loop
{
count--; // Decrement Count by 1
lcd.setCursor(0, 1);
if(10 > count);{
lcd.print("0");
}
if(count < 0) {
count = 0;
}
lcd.print(count);
delay(400);
}
}
[\code]