#include <Arduino.h>
#include <LiquidCrystal_I2C.h>
#include "Tools.hpp"
constexpr byte LEFT_PIN {A3}; // Beispiel-Pin für die 'Left'-Taste, bitte anpassen
constexpr byte RIGHT_PIN {A0}; // Beispiel-Pin für die 'Right'-Taste, bitte anpassen
constexpr unsigned long WAIT_INTERVAL_MS {200};
constexpr byte DISPLAY_SPALTEN {16};
constexpr byte DISPLAY_ZEILEN {2};
constexpr char text[] {" Das ist ein Testlauf"};
LiquidCrystal_I2C lcd(0x27, DISPLAY_SPALTEN, DISPLAY_ZEILEN);
Tools::Interval wait;
auto smaller = [](byte a, byte b) { return a < b; };
//////////////////////////////////////////////////
// Initialisierungsteil
//////////////////////////////////////////////////
void setup() {
Serial.begin(115200);
lcd.init();
lcd.backlight();
lcd.print(text);
}
//////////////////////////////////////////////////
// Hauptprogramm
//////////////////////////////////////////////////
void loop() {
static byte textLen {strlen(text)};
static bool doScrollLeft{false};
static bool doScrollRight{false};
static byte index {0};
if (!(doScrollLeft | doScrollRight)) {
doScrollLeft = (analogRead(LEFT_PIN) < 100) ? true : false;
doScrollRight = (analogRead(RIGHT_PIN) < 100) ? true : false;
index = 0;
}
if (doScrollLeft && wait(WAIT_INTERVAL_MS)) {
lcd.scrollDisplayLeft();
doScrollLeft=smaller(++index, textLen);
}
if (doScrollRight && wait(WAIT_INTERVAL_MS)) {
lcd.scrollDisplayRight();
doScrollRight=smaller(++index, textLen);
}
}