/*
Wokwi | questions
Help
Sisco - Monday, January 12, 2026 7:07 AM
I need help in coding
*/
#include <LiquidCrystal_I2C.h>
const char* LYRICS[] = {
"Of all the ones that begged to stay",
"I'm still longing for you",
"Of all the ones that cried their way",
"I'm still waiting on you",
"Maybe we seek for something that we couldn't ever have",
"Maybe we choose the only love we know we won't accept",
"Or maybe we're taking all the risks for something that is real",
"Cause maybe the greatest love of all is who the eyes can't see yeah"
};
// Timing for each line (ms)
const unsigned long LINE_DELAY[] = {
3500, 3000, 3500, 3000,
6000, 6000, 6500, 8000
};
const int TOTAL_LINES = sizeof(LYRICS) / sizeof(LYRICS[0]);
const int COLS = 20;
const int ROWS = 4;
LiquidCrystal_I2C lcd(0x27, COLS, ROWS);
void printLine(uint8_t line, const char* text) {
if (line >= ROWS) return; // prevent overflow
lcd.setCursor(0, line);
for (int i = 0; i < COLS; i++) { // clear line
lcd.print(' ');
}
lcd.setCursor(0, line);
lcd.print(text);
}
void wrapTextForLCD(const char* text, uint8_t lcdWidth,
void (*lineCallback)(uint8_t line, const char* content))
{
char buffer[lcdWidth + 1];
uint8_t line = 0;
uint8_t pos = 0;
buffer[0] = '\0';
while (*text) {
//Serial.println(pos);
// Skip leading spaces
while (*text == ' ') text++;
if (*text == '\0') break;
// Extract next word
char word[32];
uint8_t wlen = 0;
while (*text && *text != ' ' && wlen < sizeof(word) - 1) {
word[wlen++] = *text++;
}
word[wlen] = '\0';
//Serial.println(word); // prints words including one that overflows width
// If word doesn't fit on this line, flush line
if (pos && pos + 1 + wlen > lcdWidth) {
buffer[pos] = '\0';
lineCallback(line++, buffer);
Serial.println(buffer); // prints lines except last
pos = 0; // reset pos for next line
}
// Add space if needed
if (pos) {
buffer[pos++] = ' ';
}
// Copy word
for (uint8_t i = 0; i < wlen && pos < lcdWidth; i++) {
buffer[pos++] = word[i];
//Serial.println(buffer); // prepend chars to buffer
}
}
// Flush last line
if (pos) {
buffer[pos] = '\0';
lineCallback(line, buffer);
Serial.println(buffer); // prints last line only
Serial.println();
}
}
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
}
void loop() {
for (int line = 0; line < TOTAL_LINES; line++) {
wrapTextForLCD(LYRICS[line], COLS, printLine);
//Serial.println(LYRICS[line]);
delay(LINE_DELAY[line]);
lcd.clear();
}
delay(2000); // pause 2 seconds, repeat
}