Skip to content

berkay-yalin/ELE00046C-S2-A-Electronics-Project-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ELE00046C-S2-A-Electronics-Project-1

Electronics Project 1 - ELE00046C

Resources

LCD1602 Custom class

The LCD1602 library possesses the following methods:

  • display_string
  • create_char
  • display_char
  • locate
  • clear

Each method is described below with examples.

display_string

Print a string onto the LCD display (basically a printf wrapper).

#include "mbed.h"
#include "LCD1602.hpp"

LCD1602::LCD1602 lcd(D0, D1, D4, D5, D6, D7);

int main() {
    lcd.display_string("Hello World!");
}

create_char & display_char

Displaying custom characters using the mbedLCD library can become quite monotonous as:

  • you have to constantly update the position of the cursor so characters don't write over each other
  • characters are referenced in functions through their memory location which damages code readability

as can be seen in the example below:

#include <string>
#include <vector>

#include "mbed.h"
#include "LCD.h"

uint8_t heart[8] = {0b00000, 0b01010, 0b11111, 0b11111, 0b11111, 0b01110, 0b00100, 0b00000};
uint8_t diamond[8] = {0b00000, 0b00100, 0b01110, 0b11111, 0b11111, 0b01110, 0b00100, 0b00000};
uint8_t spade[8] = {0b00000, 0b00100, 0b01110, 0b11111, 0b11111, 0b00100, 0b01110, 0b00000};
uint8_t club[8] = {0b00000, 0b01110, 0b01110, 0b11111, 0b11111, 0b00100, 0b01110, 0b00000};

LCD lcd(D0, D1, D4, D5, D6, D7, LCD16x2);

int main() {
    lcd.create(1, club);
    lcd.create(2, diamond);
    lcd.create(3, heart);
    lcd.create(4, spade);

    int column = 0;
    int row = 0;

    lcd.character(column, row, 1);
    column += 1;
    lcd.locate(column, row);

    lcd.character(column, row, 2);
    column += 1;
    lcd.locate(column, row);

    lcd.character(column, row, 3);
    column += 1;
    lcd.locate(column, row);

    lcd.character(column, row, 4);
    column += 1;
    lcd.locate(column, row);
}

The LCD1602 class automatically keeps track of the cursor's location and allows you to reference the characters through an easily identifiable string:

#include <string>
#include <vector>

#include "mbed.h"
#include "LCD1602.hpp"

uint8_t heart[8] = {0b00000, 0b01010, 0b11111, 0b11111, 0b11111, 0b01110, 0b00100, 0b00000};
uint8_t diamond[8] = {0b00000, 0b00100, 0b01110, 0b11111, 0b11111, 0b01110, 0b00100, 0b00000};
uint8_t spade[8] = {0b00000, 0b00100, 0b01110, 0b11111, 0b11111, 0b00100, 0b01110, 0b00000};
uint8_t club[8] = {0b00000, 0b01110, 0b01110, 0b11111, 0b11111, 0b00100, 0b01110, 0b00000};

LCD1602::LCD1602 lcd(D0, D1, D4, D5, D6, D7);

int main() {
    lcd.create_char("club", club);
    lcd.create_char("diamond", diamond);
    lcd.create_char("heart", heart);
    lcd.create_char("spade", spade);

    lcd.display_char("club");
    lcd.display_char("diamond");
    lcd.display_char("heart");
    lcd.display_char("spade");
}

locate

Locate cursor to a position on the screen.

Keep in mind the 16x2 screen dimensions as attempting to going over the bounds will cause problems.

#include "mbed.h"
#include "LCD1602.hpp"

LCD1602::LCD1602 lcd(D0, D1, D4, D5, D6, D7);

int main() {
    lcd.locate(1, 4);
}

clear

Clear the screen and locate the cursor to (0, 0).

#include "mbed.h"
#include "LCD1602.hpp"

LCD1602::LCD1602 lcd(D0, D1, D4, D5, D6, D7);

int main() {
    lcd.clear();
}

About

ELE00046C-S2-A Electronics Project 1

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages