/* * Module 4: The I2C Display * Goal: Master External Libraries and I2C Communication */
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD.
// 0x27 is the common I2C address. 16 is columns, 2 is rows. LiquidCrystal_I2C lcd(0x27, 16, 2);
const int LDR_PIN = A0;
void setup() {
lcd.init(); // Start the LCD
lcd.backlight(); // Turn on the backlight
lcd.setCursor(0, 0); // (Column 0, Row 0)
lcd.print(“Smart System”);
lcd.setCursor(0, 1); // (Column 0, Row 1) lcd.print(“Initializing…”);
delay(2000);
lcd.clear(); }
void loop() {
int lightLevel = analogRead(LDR_PIN);
// Row 0: Constant Label
lcd.setCursor(0, 0);
lcd.print(“Light Level:”);
// Row 1: Dynamic Data
lcd.setCursor(0, 1);
lcd.print(lightLevel);
lcd.print(” “); // “Clearing” space for smaller numbers // Status message
if (lightLevel < 400) {
lcd.setCursor(8, 1);
lcd.print(“[DARK]”);
} else {
lcd.setCursor(8, 1);
lcd.print(“[OK] “);
} delay(200);
}