#include <LiquidCrystal_I2C.h>
#define incButton 2
#define onButton 3
#define offButton 4
LiquidCrystal_I2C lcd(0x27, 16, 2);
bool ledky[4] = {0, 0, 0, 0};
String menu[4] = {"LED 1", "LED 2", "LED 3", "LED 4"};
byte poloha = 0;
bool zmena = true;
void setup()
{
pinMode(incButton, INPUT_PULLUP);
pinMode(onButton, INPUT_PULLUP);
pinMode(offButton, INPUT_PULLUP);
DDRB |= 0b00001111;
PORTB &= 0b11110000;
lcd.init();
lcd.backlight();
}
void loop()
{
if (zmena)
{
for (byte ledka = 0; ledka < 4; ledka++)
if (ledky[ledka])
PORTB |= 1 << (3 - ledka);
else
PORTB &= ~(1 << (3 - ledka));
lcd.clear();
lcd.print(">");
for (byte i = 0; i < 2; i++)
{
lcd.setCursor(1, i);
if ((poloha + i) < 4)
{
lcd.print(menu[poloha + i]);
lcd.setCursor(11, i);
if (ledky[poloha + i])
lcd.print("ON");
else
lcd.print("OFF");
}
else
{
lcd.print(menu[poloha + i - 4]);
lcd.setCursor(11, i);
if (ledky[poloha + i - 4])
lcd.print("ON");
else
lcd.print("OFF");
}
}
zmena = false;
}
checkButtons();
}
void checkButtons()
{
static unsigned long lastIncButtonTime = 0;
static unsigned long lastOnButtonTime = 0;
static unsigned long lastOffButtonTime = 0;
static const unsigned long debounceDelay = 50; // debounce čas v milisekundách
if ((millis() - lastIncButtonTime) > debounceDelay)
{
if (digitalRead(incButton) == LOW)
{
zmena = true;
if (poloha < 3)
poloha++;
else
poloha = 0;
lastIncButtonTime = millis();
}
}
if ((millis() - lastOnButtonTime) > debounceDelay)
{
if (digitalRead(onButton) == LOW)
{
zmena = true;
ledky[poloha] = true; // Zapnutie príslušnej LED
lastOnButtonTime = millis();
}
}
if ((millis() - lastOffButtonTime) > debounceDelay)
{
if (digitalRead(offButton) == LOW)
{
zmena = true;
ledky[poloha] = false; // Vypnutie príslušnej LED
lastOffButtonTime = millis();
}
}
}