// Fnu Shoaib Ahmed, 652420658, fahme8
// Lab 3 - Liquid Crystal Display - LCD
// Description - This code is designed to power up an LCD with 2 lines of text. The first line is a scrolling quote,
// and the second line is a centered name displayed at all times.
// Assumptions - The potentiometer will control display brightness and the wiring is correct.
// References - I used the prelab links to set up the LCD and the potentiometer.
#include <LiquidCrystal.h>
// Initialize the library with the pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char name[] = "652420658";
char quote[] = "Aspire to Inspire before you Expire... "; // Longer quote for scrolling
int quoteIndex = 0;
unsigned long previousMillis = 0;
const long interval = 300; // Adjust the scrolling speed (milliseconds)
void setup() {
// Set up the LCD's number of columns and rows
lcd.begin(16, 2);
// Use sprintf() to format the name string
char formattedName[40]; // Buffer for the formatted name (16 characters + null terminator)
int padding = (16 - strlen(name)) / 2; // Calculate the padding to center the name
sprintf(formattedName," %s ","Shoaib"); // Format the name with padding
// Display the centered name on the second line
lcd.setCursor(0, 1); // Start at the beginning of the second line
lcd.print(formattedName); // Print the formatted name
}
void loop() {
unsigned long currentMillis = millis();
// Check if enough time has passed for scrolling
if (currentMillis - previousMillis >= interval) {
// Save the current time
previousMillis = currentMillis;
// Scroll the quote on the first line
lcd.setCursor(0, 0);
for (int i = 0; i < 16; i++) {
lcd.print(quote[(quoteIndex + i) % strlen(quote)]);
}
// Move to the next character in the quote
quoteIndex++;
if (quoteIndex >= strlen(quote)) {
quoteIndex = 0; // Reset to the beginning of the quote
}
}
}