#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define SDA 21
#define SCL 22
#define BUT_UP 26
#define BUT_DN 27
LiquidCrystal_I2C lcd(0x27, 16, 2);
byte arrows[8] = {0b00100,0b01110,0b11111,0b00000,0b11111,0b01110,0b00100,0b00000};
// Textové pole: [index][řádek]
const char* text[][2] = {
//xxxxxxxxxxxxxxx
{"Stopwatch 12:30", "(0-12hod [0])"},
{"Stopwatch off", "(0-12hod [0])"},
{"15:30 15.11.2025", "[0] set date/time"},
{"WiFi on", "SSID: SUNREG Wi"}
};
int textIndex = 0;
const int textCount = sizeof(text) / sizeof(text[0]);
void setup() {
Serial.begin(115200);
pinMode(BUT_UP, INPUT_PULLUP);
pinMode(BUT_DN, INPUT_PULLUP);
Wire.begin(SDA, SCL);
lcd.init();
lcd.backlight();
lcd.createChar(0, arrows); // sipky up down symbol
showTextOnLcd(textIndex);
}
void loop() {
// Tlačítko UP
if (digitalRead(BUT_UP) == LOW) {
textIndex++;
if (textIndex >= textCount) textIndex = 0;
showTextOnLcd(textIndex);
delay(300);
}
// Tlačítko DOWN
if (digitalRead(BUT_DN) == LOW) {
textIndex--;
if (textIndex < 0) textIndex = textCount - 1;
showTextOnLcd(textIndex);
delay(300);
}
}
void showTextOnLcd(int num) {
lcd.clear();
lcd.setCursor(0, 0);
printWithSpecials(text[num][0]);
lcd.setCursor(0, 1);
printWithSpecials(text[num][1]);
}
void printWithSpecials(const char* str) {
int i = 0;
while (str[i] != '\0' && i < 16) {
if (str[i] == '[' && str[i+2] == ']' && isdigit(str[i+1])) {
int index = str[i+1] - '0'; // převod ASCII čísla na int
lcd.write(index);
i += 3; // přeskočíme "[x]"
} else {
lcd.print(str[i]);
i++;
}
}
}