#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define buttonNext 14 // Pin for the "Next" button
#define buttonPrev 15 // Pin for the "Previous" button
// Set the LCD address to 0x27 for a 16 chars and 2-line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
int led_num = 1; // Start with Mode 1
void setup() {
lcd.init();
lcd.backlight(); // Turn on the backlight
lcd.setCursor(0, 0);
lcd.print("Display test.");
pinMode(buttonNext, INPUT);
pinMode(buttonPrev, INPUT);
digitalWrite(buttonNext, LOW);
digitalWrite(buttonPrev, LOW);
delay(1000); // Display "Hello, fayy!" for 1 second
}
void loop() {
int valNext = digitalRead(buttonNext); // Read the "Next" button state
int valPrev = digitalRead(buttonPrev); // Read the "Previous" button state
if (valNext == HIGH) {
led_num = led_num + 1;
if (led_num > 3) led_num = 1; // Wrap around to Mode 1 if it exceeds 3
delay(200); // Debounce delay
}
if (valPrev == HIGH) {
led_num = led_num - 1;
if (led_num < 1) led_num = 3; // Wrap around to Mode 3 if it goes below 1
delay(200); // Debounce delay
}
lcd.clear();
if (led_num == 1) {
lcd.setCursor(0, 0);
lcd.print("Mode 1");
} else if (led_num == 2) {
lcd.setCursor(0, 0);
lcd.print("Mode 2");
} else if (led_num == 3) {
lcd.setCursor(0, 0);
lcd.print("Mode 3");
}
delay(300); // Optional delay to slow down the loop
}