#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x27,16,2);
int buttonPin = 35;
int numberKeyPresses = 0;
bool pressed = false;
volatile unsigned long button_time = 0;
volatile unsigned long last_button_time = 0;
int counter = 0;
int state = 0;
void IRAM_ATTR count() {
button_time = millis();
if(button_time - last_button_time > 250){
numberKeyPresses++;
pressed = true;
last_button_time = button_time;
}
state = 1;
}
void setup() {
pinMode(5, OUTPUT);
pinMode(34, INPUT_PULLUP);
Serial.begin(115200);
pinMode (35, INPUT_PULLUP);
attachInterrupt (35, count, RISING);
lcd.init();
lcd.backlight();
}
void loop() {
for(int i = 0; i < 11; i++){
lcd.setCursor(1,0);
lcd.print("counter:"); lcd.print(i);
delay(1000);
}
digitalWrite(5,state);
if (pressed) {
Serial.println("Button has been pressed " + String (numberKeyPresses) + "times");
pressed = false;
}
}