#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // Set the LCD address to 0x27 for a 20x4 display
const int enterButton = 2; // Button pin for Enter
const int setButton = 3; // Button pin for Set Set
const int resetButton = 4; // Button pin for Reset
unsigned long previousMillis = 0;
const long interval = 1000; // Update interval for the clock display
int step = 0;
void setup() {
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
pinMode(enterButton, INPUT_PULLUP); // Set Enter button as input with internal pull-up resistor
pinMode(setButton, INPUT_PULLUP); // Set Set button as input with internal pull-up resistor
pinMode(resetButton, INPUT_PULLUP); // Set Reset button as input with internal pull-up resistor
}
void loop() {
unsigned long currentMillis = millis();
// Check the current step and display the corresponding text
switch (step) {
case 0: // Display "VINCE JULIAN S. DAY" for 3 seconds
if (currentMillis < 3000) {
lcd.setCursor(0, 0);
lcd.print("VINCE JULIAN S. DAY");
} else if (currentMillis < 4000) {
lcd.clear();
} else {
step = 1; // Move to the next step
}
break;
case 1: // Display "BSIT 2-A ELX" for 3 seconds
if (currentMillis < 7000) {
lcd.setCursor(0, 0);
lcd.print("BSIT 2-A ELX");
} else if (currentMillis < 8000) {
lcd.clear();
} else {
step = 2; // Move to the next step
}
break;
case 2: // Display "SMART FISH AQUARIUM" for 2 seconds
if (currentMillis < 10000) {
lcd.setCursor(0, 0);
lcd.print("SMART FISH AQUARIUM");
} else if (currentMillis < 12000) {
lcd.clear();
} else {
step = 3; // Move to the next step
}
break;
case 3: // Show the time and date May 9, 2024 11:29pm
if (currentMillis < 16000) {
lcd.setCursor(0, 0);
lcd.print("Date: May 9, 2024");
lcd.setCursor(0, 1);
lcd.print("Time: 11:46 PM");
} else {
// Digital clock function using buttons Enter, Set, and Reset
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
// Get the current time
int hours = (currentMillis / 1000 / 3600) % 24;
int minutes = (currentMillis / 1000 / 60) % 60;
int seconds = (currentMillis / 1000) % 60;
lcd.setCursor(0, 2);
lcd.print("Current Time: ");
if (hours < 10) {
lcd.print("0");
}
lcd.print(hours);
lcd.print(":");
if (minutes < 10) {
lcd.print("0");
}
lcd.print(minutes);
lcd.print(":");
if (seconds < 10) {
lcd.print("0");
}
lcd.print(seconds);
}
}
break;
}
// Check if buttons are pressed
if (digitalRead(enterButton) == LOW) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Button Pressed");
delay(1000);
}
if (digitalRead(setButton) == LOW) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set Button Pressed");
delay(1000);
}
if (digitalRead(resetButton) == LOW) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Reset Button Pressed");
delay(1000);
}
}