#include <LiquidCrystal_I2C.h>
//declaration of the display
LiquidCrystal_I2C lcd(0x27,16,2);
// Pin configuration
const int buttonPin = D4; // change as needed
// Counter variable
int counter = 0;
// To track the button state
bool lastButtonState = HIGH;
void setup() {
pinMode(buttonPin, INPUT_PULLUP); // Enable internal pull-up resistor
Serial.begin(9600);
// lcd.init();
// lcd.backlight();
// lcd.setCursor(3,0);
// lcd.print("Hello, world!");
// lcd.setCursor(2,1);
// lcd.print("Ywrobot Arduino!");
}
void loop() {
bool currentButtonState = digitalRead(buttonPin);
// Detect falling edge (HIGH to LOW)
if (lastButtonState == HIGH && currentButtonState == LOW) {
counter++;
Serial.print("Button pressed! Count = ");
Serial.println(counter);
delay(200); // basic debouncing
}
lastButtonState = currentButtonState;
}