// include desired libraries
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 4, 20);
int rightButton = 13; // Down-Button als Rechts-Button verwenden
int leftButton = 12; // Up-Button als Links-Button verwenden
int selectButton = 11;
int menu = 1; // Starten Sie mit dem Hauptmenü "Select Duration"
int selectedDuration = 0; // Variable für die ausgewählte Laufzeit in Stunden
unsigned long startTime = 0; // Startzeit des Timers
unsigned long durationInSeconds = 0; // Gesamtdauer in Sekunden
const int submenuCount = 11; // Anzahl der verfügbaren Laufzeiten
const char* submenuItems[submenuCount] = {"2", "6", "24", "48", "96", "168", "240", "480", "720", "1008", "1440"}; // Ergänzte Durations
void updateMenu() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Select Duration: (h)");
int number_of_characters = 0;
for (int i = 0; i < submenuCount; i++) {
String write_to_lcd = "";
// add brackets to menu item
if (i + 1 == menu) {
write_to_lcd = write_to_lcd + "[" + submenuItems[i] + "]";
}
else{
write_to_lcd = write_to_lcd + submenuItems[i];
}
if (i < submenuCount - 1){
// add space after durations except the last one
write_to_lcd = write_to_lcd + " ";
}
// check if the size of string overflows the remaining characters in the lcd row
int remaining_characters_in_row = 20 - (number_of_characters % 20);
if (remaining_characters_in_row < write_to_lcd.length()){
number_of_characters = number_of_characters + remaining_characters_in_row;
}
lcd.setCursor(number_of_characters % 20, (number_of_characters / 20) + 1);
lcd.print(write_to_lcd);
number_of_characters = number_of_characters + write_to_lcd.length();
}
}
void setup() {
lcd.init();
lcd.backlight();
pinMode(rightButton, INPUT_PULLUP);
pinMode(leftButton, INPUT_PULLUP);
pinMode(selectButton, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), blinkLed, RISING);
updateMenu();
}
void loop(){
delay(10);
}