// #include <LiquidCrystal_I2C.h>
// // Initialize the LCD (I2C address: 0x27, dimensions: 20x4)
// LiquidCrystal_I2C lcd(0x27, 20, 4);
// // Array of sentences to scroll
// String texts[] = {
// "Mehanas daughter of Muneer",
// "Mehanas daughter of Jeseena",
// "Mehanas sister of Ahmed Jahis",
// "Thanku Rajesh buddy"
// };
// int textCount = sizeof(texts) / sizeof(texts[0]); // Number of sentences
// int scrollDelay = 300; // Delay in milliseconds for scrolling
// void setup() {
// lcd.init(); // Initialize the LCD
// lcd.backlight(); // Turn on the backlight
// lcd.clear(); // Clear the display
// }
// void loop() {
// for (int i = 0; i < textCount; i++) {
// scrollText(texts[i]); // Scroll each sentence
// delay(1000); // Pause before displaying the next sentence
// }
// }
// void scrollText(String text) {
// int len = text.length();
// if (len <= 20) {
// // If the text fits, display it directly
// lcd.clear();
// lcd.setCursor(0, 0); // Start at the first row
// lcd.print(text);
// delay(2000); // Hold the text for 2 seconds
// } else {
// // Scroll the text horizontally
// for (int position = 0; position < len - 19; position++) {
// lcd.clear();
// lcd.setCursor(0, 0); // Start at the first row
// lcd.print(text.substring(position, position + 20)); // Display 20 characters at a time
// delay(scrollDelay);
// }
// }
// }
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// LCD display setup
LiquidCrystal_I2C lcd(0x27, 16, 4);
// Button pin
const int buttonPin = 2;
// Timer variables
unsigned long startTime = 0;
bool timerRunning = false;
void setup() {
// Initialize the LCD
lcd.begin();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Count-Up Timer");
// Initialize the button pin
pinMode(buttonPin, INPUT);
}
void loop() {
// Read the button state
int buttonState = digitalRead(buttonPin);
// Check if the button is pressed
if (buttonState == HIGH) {
if (!timerRunning) {
// Start the timer
startTime = millis();
timerRunning = true;
} else {
// Stop and reset the timer
timerRunning = false;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Count-Up Timer");
}
// Debounce delay
delay(200);
}
// Update the timer display if running
if (timerRunning) {
unsigned long elapsedTime = millis() - startTime;
unsigned long seconds = (elapsedTime / 1000) % 60;
unsigned long minutes = (elapsedTime / 60000) % 60;
unsigned long hours = (elapsedTime / 3600000);
lcd.setCursor(0, 1);
lcd.print("Time: ");
lcd.print(hours);
lcd.print(":");
lcd.print(minutes);
lcd.print(":");
lcd.print(seconds);
}