#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
#define BUTTON1 2
#define BUTTON2 3
#define BUTTON3 4
#define LED1 5
#define LED2 6
#define LED3 7
bool ledState1 = LOW;
bool ledState2 = LOW;
bool ledState3 = LOW;
//button1
int buttonState1 = LOW;
int lastButtonState1 = LOW;
long lastDebounceTime1 = 0;
long debounceDelay = 50;
//button2
int buttonState2 = LOW;
int lastButtonState2 = LOW;
long lastDebounceTime2 = 0;
//button3
int buttonState3 = LOW;
int lastButtonState3 = LOW;
long lastDebounceTime3 = 0;
void setup() {
lcd.init();
lcd.backlight();
pinMode(BUTTON1, INPUT);
pinMode(BUTTON2, INPUT);
pinMode(BUTTON3, INPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print("kontrola stavu TL:");
}
void loop() {
//LED1
int reading1 = digitalRead(BUTTON1);
if (reading1 != lastButtonState1) {
lastDebounceTime1 = millis();
}
if ((millis() - lastDebounceTime1) > debounceDelay) {
if (reading1 != buttonState1) {
buttonState1 = reading1;
if (buttonState1 == HIGH) {
ledState1 = !ledState1;
digitalWrite(LED1, ledState1);
zobraz();
}
}
}
lastButtonState1 = reading1;
//LED2
int reading2 = digitalRead(BUTTON2);
if (reading2 != lastButtonState2) {
lastDebounceTime2 = millis();
}
if ((millis() - lastDebounceTime2) > debounceDelay) {
if (reading2 != buttonState2) {
buttonState2 = reading2;
if (buttonState2 == HIGH) {
ledState2 = !ledState2;
digitalWrite(LED2, ledState2);
zobraz();
}
}
}
lastButtonState2 = reading2;
//LED3
int reading3 = digitalRead(BUTTON3);
if (reading3 != lastButtonState3) {
lastDebounceTime3 = millis();
}
if ((millis() - lastDebounceTime3) > debounceDelay) {
if (reading3 != buttonState3) {
buttonState3 = reading3;
if (buttonState3 == HIGH) {
ledState3 = !ledState3;
digitalWrite(LED3, ledState3);
zobraz();
}
}
}
lastButtonState3 = reading3;
}
void zobraz() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("kontrola stavu TL:");
lcd.setCursor(0, 1);
if (ledState1) {
lcd.print("TL1 - stlacene");
}
lcd.setCursor(0, 2);
if (ledState2) {
lcd.print("TL2 - stlacene");
}
lcd.setCursor(0, 3);
if (ledState3) {
lcd.print("TL3 - stlacene");
}
}