#include <LiquidCrystal_I2C.h>
const int buttonPin1 = 2;
const int buttonPin2 = 3;
int button1_State = 0;
int button2_State = 0;
int count_value = 0;
int prestate1 = 0;
int prestate2 = 0;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(4, 0);
lcd.print("Counter");
lcd.setCursor(2, 1);
lcd.print(count_value);
}
void loop() {
button1_State = digitalRead(buttonPin1);
button2_State = digitalRead(buttonPin2);
if (button1_State == HIGH && prestate1 == 0) {
count_value++;
lcd.setCursor(0, 1);
lcd.print("> ");
lcd.print(count_value);
lcd.print(" ");
prestate1 = 1;
} else if (button1_State == LOW) {
prestate1 = 0;
}
if (button2_State == HIGH && prestate2 == 0) {
count_value--;
lcd.setCursor(0, 1);
lcd.print("> ");
lcd.print(count_value);
lcd.print(" ");
prestate2 = 1;
} else if (button2_State == LOW) {
prestate2 = 0;
}
}