// LAB 2; ADRIANA SARAH BINTI AHMAD FAIZA ; 52224123439
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// define custom characters
byte heart[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000
};
byte smiley[8] = {
0b00000,
0b00000,
0b01010,
0b00000,
0b00000,
0b10001,
0b01110,
0b00000
};
void setup() {
lcd.begin(16, 2);
// to create the custom characters
lcd.createChar(0, heart);
lcd.createChar(1, smiley);
}
void loop() {
// task a: initialize the display, add text, and move the cursor
lcd.clear();
lcd.print("Hello, World!");
delay(2000);
lcd.setCursor(0, 1);
lcd.print("teddy <3");
delay(2000);
lcd.clear();
// task b: create and display custom characters
lcd.setCursor(0, 0);
lcd.write(byte(0));
lcd.setCursor(1, 0);
lcd.write(byte(1));
delay(2000);
lcd.clear();
// task c: display special symbols
lcd.print("Temp: ");
lcd.print((char)223); // degree symbol
lcd.print("C");
delay(2000);
lcd.clear();
// task d: animate custom characters
for (int i = 0; i < 16; i++) {
lcd.setCursor(i, 0);
lcd.write(byte(0));
delay(200);
lcd.setCursor(i, 0);
lcd.print(" ");
}
// debugging display
lcd.setCursor(0, 1);
lcd.print("Debug: Done");
delay(2000);
}