#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust the I2C address if necessary
enum Message {
HELLO,
WELCOME_TO_AAU,
RTGP_SPRING_2024,
MESSAGE_COUNT // Number of messages
};
volatile bool buttonPressed = false;
volatile Message currentMessage = HELLO;
void setup() {
Serial.begin(9600); // Initialize serial communication
while (!Serial); // Wait for the serial monitor to open
pinMode(2, INPUT_PULLUP); // Set pin 2 (INT0) as input with internal pull-up resistor
attachInterrupt(digitalPinToInterrupt(2), buttonInterrupt, FALLING); // Attach interrupt to pin 2
lcd.begin(16, 2); // Initialize LCD
lcd.print("Hello!"); // Print initial message
}
void loop() {
// Check if button is pressed
if (buttonPressed) {
// Increment current message
currentMessage = static_cast<Message>((currentMessage + 1) % MESSAGE_COUNT);
displayMessage(currentMessage); // Display message
delay(500); // Debounce delay
buttonPressed = false; // Reset buttonPressed flag
}
}
void displayMessage(Message message) {
lcd.clear(); // Clear the LCD screen
// Print message based on enumeration
switch (message) {
case HELLO:
lcd.print("Hello!");
break;
case WELCOME_TO_AAU:
lcd.print("Welcome to AAU");
break;
case RTGP_SPRING_2024:
lcd.print("RTGP Spring 2024");
break;
default:
break;
}
}
void buttonInterrupt() {
buttonPressed = true; // Set buttonPressed flag
}