#include <LiquidCrystal.h>
constexpr byte led1 = 10;
constexpr byte button = A5;
int val;
int points = 0;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
constexpr unsigned long BLINK_DELAY {1500};
unsigned long delayStart;
void setup() {
Serial.begin(115200);
lcd.begin(16, 2);
pinMode(button, INPUT);
pinMode(led1, OUTPUT);
delayStart = BLINK_DELAY;
}
void loop() {
static bool isLedOn {false};
static bool doCount {false};
if (millis() - delayStart > BLINK_DELAY) {
delayStart = millis();
(isLedOn = !isLedOn) ? digitalWrite(led1, HIGH) : digitalWrite(led1, LOW);
doCount = (val == HIGH) ? false : true; // A continuous keystroke must not increase the counter.
}
val = digitalRead(button);
if (val == HIGH && isLedOn == true && doCount == true) {
++points;
doCount = false;
Serial.println(points);
lcd.setCursor(0, 0);
lcd.print("Points");
lcd.setCursor(0, 1);
lcd.print(points);
}
}