/* * ============================================================ * 16×2 LCD Display with I2C Module (PCF8574T) — Sample Sketch * Tishvi Electronics | guide.tishvi.com * ============================================================ * Wiring (I2C — only 4 wires!): * LCD Module GND → Arduino GND * LCD Module VCC → Arduino 5V * LCD Module SDA → Arduino A4 * LCD Module SCL → Arduino A5 * * I2C Address: 0x27 (PCF8574T default) * 0x3F (PCF8574AT — try this if 0x27 does not work) * * Library required — install via Arduino IDE Library Manager: * LiquidCrystal_I2C (search: "LiquidCrystal I2C" by Frank de Brabander) * * What this sketch does: * 1. Initialises the LCD and turns on the backlight * 2. Displays a welcome message on two rows * 3. After 2 seconds, starts a live uptime counter (HH:MM:SS) * 4. Demonstrates cursor control and text clearing * ============================================================ */ #include #include // ── Display Configuration ──────────────────────────────────── // LiquidCrystal_I2C(i2c_address, columns, rows) // Try 0x3F if your display stays blank with 0x27 LiquidCrystal_I2C lcd(0x27, 16, 2); void setup() { Serial.begin(9600); // ── Initialise LCD ────────────────────────────────────── lcd.init(); lcd.backlight(); // Turn on backlight Serial.println("16x2 LCD I2C — Tishvi Sample Sketch"); Serial.println("LCD initialised."); // ── Welcome Screen ────────────────────────────────────── // Row 0 (top row) lcd.setCursor(0, 0); lcd.print(" TISHVI DOCS "); // Row 1 (bottom row) lcd.setCursor(0, 1); lcd.print(" LCD I2C Ready! "); delay(2500); // Show welcome for 2.5 seconds lcd.clear(); } void loop() { // ── Live Uptime Counter ───────────────────────────────── unsigned long totalSec = millis() / 1000; unsigned int hours = totalSec / 3600; unsigned int minutes = (totalSec % 3600) / 60; unsigned int seconds = totalSec % 60; // ── Row 0: Label ─────────────────────────────────────── lcd.setCursor(0, 0); lcd.print("Uptime: "); // ── Row 1: HH:MM:SS ──────────────────────────────────── lcd.setCursor(0, 1); // Zero-pad each component to 2 digits 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); lcd.print(" Tishvi "); // Also log to Serial Monitor Serial.print("Uptime: "); if (hours < 10) Serial.print("0"); Serial.print(hours); Serial.print(":"); if (minutes < 10) Serial.print("0"); Serial.print(minutes); Serial.print(":"); if (seconds < 10) Serial.print("0"); Serial.println(seconds); delay(1000); // Update every second }