/*
https://forum.arduino.cc/t/multiple-pages-on-i2c-lcd-display/1095011
*/
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
const uint8_t maxScreens = 3;
uint8_t currentScreen = 0;
const uint8_t btnPin = 7;
void nextScreen() {
currentScreen++;
if (currentScreen >= maxScreens) currentScreen = 0;
switch (currentScreen) {
case 0 : screenA(); break;
case 1 : screenB(); break;
case 2 : screenC(); break;
}
}
void screenA() {
lcd.clear();
lcd.print(F("A something here"));
}
void screenB() {
lcd.clear();
lcd.print(F("B different screen"));
}
void screenC() {
lcd.clear();
lcd.print(F("C another screen"));
}
void setup() {
pinMode(btnPin, INPUT_PULLUP);
lcd.init();
lcd.backlight();
lcd.print("start");
}
void loop() {
if (digitalRead (btnPin) == LOW) {
nextScreen();
delay(500); // dirty delay - use a real state change detection instead;
}
}