#include <LiquidCrystal.h>
#define PIZ 4
#define LED_PIN 13
#define BRIGHTNESS 255
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
volatile int timeSec = 10;
volatile int s = timeSec;
uint64_t lastTime = 0;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Time: ");
lcd.print(s);
lcd.print(" s ");
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(PIZ, OUTPUT);
attachInterrupt(0, pravo, FALLING);
attachInterrupt(1, levo, FALLING);
lastTime = millis();
}
void loop() {
if (s == 0) {
tone(PIZ, 2000, 3000);
delay(3000);
s = timeSec;
}
else {
if (millis() - lastTime > 1000) {
lastTime = millis();
s--;
}
lcd.setCursor(6, 0);
lcd.print(s);
lcd.print(" s ");
}
}
void pravo() {
s++;
timeSec++;
}
void levo() {
s = s > 0 ? s - 1 : 0;
timeSec = timeSec > 1 ? timeSec-- : 1;
}