#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.begin(16, 2);
// Task 1.2 (a): Display Text and Move Cursor
lcd.setCursor(0, 0);
lcd.print("Hello!");
delay(2000);
// Move cursor to next column
lcd.setCursor(7, 0);
lcd.print("I'm Uwais!");
delay(2000);
// Move cursor and print on second line
lcd.setCursor(2, 1);
lcd.print("Welcome ^_^");
delay(2000);
lcd.clear();
}
void loop() {
// Task 1.2 (b): Creating Special Characters
byte smiley[8] = {
0b00000,
0b01010,
0b01010,
0b00000,
0b10001,
0b01110,
0b00000,
0b00000,
};
lcd.createChar(0, smiley);
lcd.setCursor(0, 0);
lcd.write(byte(0));
lcd.print(" Smile!");
delay(2000);
byte sad[8] = {
0b00000,
0b01010,
0b00000,
0b00000,
0b01110,
0b10001,
0b00000,
0b00000,
};
lcd.createChar(1, sad);
lcd.setCursor(0, 1);
lcd.write(byte(1));
lcd.print(" Sad!");
delay(2000);
// Task 1.2 (c): Display Special Symbols
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.write(223); // Degree symbol
lcd.print("C");
delay(2000);
// Task 1.2 (d): Creating Custom Characters
byte snowflake[8] = {
0b00100,
0b10101,
0b01110,
0b11111,
0b01110,
0b10101,
0b00100,
0b00000
};
lcd.createChar(1, snowflake);
// Animation: Move Snowflake Across the Screen
for (int row = 0; row < 2; row++) { // Loop through rows
for (int col = 0; col < 16; col++) { // Loop through columns
lcd.clear(); // Clear previous position
lcd.setCursor(col, row); // Set new position
lcd.write(byte(1)); // Draw snowflake
delay(200); // Pause to create animation effect
}
}
for (int row = 1; row >= 0; row--) { // Loop back through rows in reverse
for (int col = 15; col >= 0; col--) { // Loop through columns in reverse
lcd.clear(); // Clear previous position
lcd.setCursor(col, row); // Set new position
lcd.write(byte(1)); // Draw snowflake
delay(200); // Pause to create animation effect
}
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Snowflake");
delay(2000);
lcd.setCursor(0, 1);
lcd.print(" Animation!");
delay(2000);
lcd.clear();
}