#include <LiquidCrystal_I2C.h>
#define SDA A4
#define SCL A5
#define BUZZER 4
#define TLACITKO 5
LiquidCrystal_I2C lcd(0x27, 16, 2);
byte customChar[8] = {
0b10001,
0b10001,
0b11011,
0b01010,
0b01110,
0b00100,
0b01110,
0b10001
};
int cislo = 10;
bool stav = false;
int buttonState = LOW;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0;
uint8_t debounceInterval = 50;
unsigned long previousMillis = 0;
void setup() {
pinMode(TLACITKO, INPUT);
lcd.init();
lcd.backlight();
lcd.createChar(0, customChar); // create a new custom character
lcd.setCursor(2, 0); // move cursor to (2, 0)
lcd.write((byte)0); // print the custom char at (2, 0)
lcd.setCursor(5, 1);
lcd.print(cislo);
}
void loop() {
int reading = digitalRead(TLACITKO);
if(millis() - previousMillis >= 1000 && stav){
previousMillis = millis();
lcd.print(cislo--);
if(cislo == 0)
{
stav = false;
tone(BUZZER, 262, 1000);
}
}
if(reading != lastButtonState){
lastDebounceTime = millis();
}
if((millis() - lastDebounceTime) >= debounceInterval){
if(reading != buttonState) {
if(buttonState == HIGH && !stav){
stav = true;
cislo = 10;
}
}
buttonState = reading;
}
}