#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#define BUTTON 6
#define LIMIT 20
uint8_t cas = LIMIT;
boolean stav = true; //1- bezi, 0-stoji
unsigned long previousMillis = 0;
int buttonState = LOW;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
byte znak[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000,
0b00000
};
void setup() {
pinMode(BUTTON, INPUT);
lcd.init();
lcd.backlight();
lcd.createChar(0, znak);
lcd.setCursor(10, 0); // move cursor to (2, 0)
lcd.write((byte)0);
}
void loop() {
unsigned long currentMillis = millis();
if(currentMillis-previousMillis >=1000 && stav){
previousMillis = currentMillis;
lcd.setCursor(5,1);
zobraz();
}
if(cas==0){
stav = false;
tone(4,262,1000);
}
int reading = digitalRead(BUTTON);
if((millis()- lastDebounceTime)>debounceDelay){
if(reading != buttonState){
buttonState = reading;
if(buttonState == HIGH && !stav){
stav= true;
cas = LIMIT;
previousMillis = millis();
zobraz();
//display.showNumberDec(cas,false);
}
}
}
lastButtonState = reading;
}
void zobraz(){
String text =(cas<=10)?" "+String(--cas):String(--cas);
lcd.setCursor(16-text.length(),1);
lcd.clear();
lcd.print(text);
lcd.setCursor(0, 1); // move cursor to (2, 0)
lcd.write((byte)0);
lcd.setCursor(1, 1); // move cursor to (2, 0)
lcd.write((byte)0);
lcd.setCursor(2, 1); // move cursor to (2, 0)
lcd.write((byte)0);
}