#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#define BUTTON 6
#define LIMIT 20
uint8_t cas = LIMIT+1;
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 i=0;
byte tulipan[8] = {
0b01010,
0b01110,
0b01110,
0b00100,
0b00101,
0b00111,
0b00110,
0b00100
};
void setup() {
pinMode(BUTTON, INPUT);
lcd.init();//lcd.backlight();
lcd.backlight();
lcd.createChar(0, tulipan); // create a new custom character
/*lcd.setCursor(1, 0); // move cursor to (2, 0)
lcd.write((byte)0); // print the custom char at (2, 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= true;
cas = LIMIT+1;
previousMillis = millis();
zobraz();
}
}
}
lastButtonState = reading;
}
void zobraz(){
lcd.clear();
String text =(cas<=10)?" "+String(--cas):String(--cas);
lcd.setCursor(16-text.length(),0);
lcd.print(text);
lcd.setCursor(i, 1); // move cursor to (2, 0)
i=(++i%16);
lcd.write((byte)0);
}