#include <LiquidCrystal_I2C.h>
#define BUTTON 5
#define LIMIT 10
unsigned long previousMillis = 0;
boolean stav = true;
bool buttonState = LOW;
bool lastButtonState = LOW;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
LiquidCrystal_I2C lcd(0x27, 16, 2);
uint8_t cas = LIMIT;
void setup() {
// put your setup code here, to run once:
pinMode(BUTTON, INPUT);
tone(4,262,500);
lcd.init(); //inicializuje
lcd.backlight(); //nastavi podsvietenie
}
void loop() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >=1000 && stav){
previousMillis = currentMillis;
cas--;
zobraz();
if(cas == 0){
tone(4,262,200);
stav = false;
}
}
int reading = digitalRead(BUTTON);
if(reading != lastButtonState) {
lastDebounceTime = millis();
}
if((millis() - lastDebounceTime) > debounceDelay) {
if(reading != buttonState) {
buttonState = reading;
if(buttonState == HIGH && !stav) {
stav = true;
cas = LIMIT;
previousMillis = millis();
zobraz();
}
else if(buttonState == HIGH && stav){
tone(4,292);
delay(100);
tone(4,192,200);
stav = false;
}
}
}
lastButtonState = reading;
}
void zobraz()
{
lcd.setCursor(7,1);
String text = (cas<10)? String(cas) : String(cas);
lcd.print(cas);
}