#include <LiquidCrystal_I2C.h>
const int buttonPin = 2;
int button_State = 0;
int count_value =0;
int prestate =0;
LiquidCrystal_I2C lcd(0x27,16,2);
void setup() {
// put your setup code here, to run once:
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(4,0);
lcd.print("Counter");
lcd.setCursor(2,1);
lcd.print(count_value);
}
void loop() {
// put your main code here, to run repeatedly:
// read the state of the pushbutton value:
button_State = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (button_State == HIGH && prestate == 0) {
count_value++;
lcd.setCursor(0,1);
lcd.print("> ");
lcd.print(count_value);
lcd.print(" ");
prestate = 1;
}
else if(button_State == LOW) {
prestate = 0;
}
}