#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int buttonPin = 2;
const int resetPin = 4;
int count = 0;
bool lastButtonState = LOW;
bool lastResetState = LOW;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(resetPin, INPUT_PULLUP);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Counter: 0");
}
void loop() {
bool buttonState = digitalRead(buttonPin);
bool resetState = digitalRead(resetPin);
if (buttonState == LOW && lastButtonState == HIGH) {
count++;
updateLCD();
}
lastButtonState = buttonState;
if (resetState == LOW && lastResetState == HIGH) {
count = 0;
updateLCD();
}
lastResetState = resetState;
delay(50);
}
void updateLCD() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Counter: ");
lcd.print(count);
}