LCD Tutorial

LCD Tutorial © GPL3+

Project that introduces interfacing with LCD module directly

  • 22 views
  • 0 comments
  • 0 respects

Components and supplies

About this project

Animation

The project is about how to use LCD module directly and introducing animations in it.

LCD module is connected to Arduino Nano with the help of jumper wires.

The code makes use of a Library <LiquidCrystal.h>

The library provides the coder with a constructor with following signature

LiquidCrystal objname(Register_Select, Enable, Pins(D0-D7 or D4-D7); //method syntax.

Code

Animation CodeC/C++
#include<LiquidCrystal.h> //Library for LCD usually store the code and library in the same directory
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);  //Constructor to create lcd object
//Aim is to create Special characters for animation
// Animation is  'x' character that contracts and expands.
//Each sub rectangle in LCD is made up of 8x5 pixels
// .....
// .....
// .....
// .....    Rectangle in LCD
// .....
// .....
// .....
// .....
// byte st [] array is used in Binary to glow a particular pixel.

byte st1[8]={B00000,B00000,B00000,B00000,B00000,B00000,B00000,B00000};
byte st2[8]={B00000,B00000,B00000,B00100,B00000,B00000,B00000,B00000};
byte st3[8]={B00000,B00000,B00100,B00100,B00100,B00000,B00000,B00000};
byte st4[8]={B00000,B01010,B00100,B00100,B00100,B01010,B00000,B00000};
byte st5[8]={B10001,B01010,B00100,B00100,B00100,B01010,B10001,B00000};
void setup() {
  //we can only create 8 chars i.e. 0-7 and they would be called as byte(num)
  lcd.createChar(0,st1);  //function used to create a new character 
  lcd.createChar(1,st2);
  lcd.createChar(2,st3);
  lcd.createChar(3,st4);
  lcd.createChar(4,st5);
  //initializing LCD module.
  lcd.begin(16, 2);       
  //Lcd is 0,0 indexing i.e diagonal from 0,0 to 15,15
  lcd.setCursor(5,0);
  lcd.print("Happy");
  lcd.setCursor(4,1);
  lcd.print("Diwali");
  //Printing simple ascii chars.
}

void loop() {
  for(int i=0;i<=4;i++)
  {
   //setting all x's at different positions
   lcd.setCursor(1,0);
   lcd.write(byte(i));
   lcd.setCursor(0,1);
   lcd.write(byte(i));
   lcd.setCursor(2,1);
   lcd.write(byte(i));
   lcd.setCursor(3,0);
   lcd.write(byte(i));
   lcd.setCursor(10,0);
   lcd.write(byte(i));
   lcd.setCursor(11,1);
   lcd.write(byte(i));
   lcd.setCursor(12,0);
   lcd.write(byte(i));
   lcd.setCursor(13,1);
   lcd.write(byte(i));
   lcd.setCursor(14,0);
   lcd.write(byte(i));
   lcd.setCursor(15,1);
   lcd.write(byte(i));
   delay(100); //delay is essential for LCD module to get commands.
  } //increasing x
  for(int i=4;i>=0;i--)
  {
      lcd.setCursor(1,0);
   lcd.write(byte(i));
   lcd.setCursor(0,1);
   lcd.write(byte(i));
   lcd.setCursor(2,1);
   lcd.write(byte(i));
   lcd.setCursor(3,0);
   lcd.write(byte(i));
   lcd.setCursor(10,0);
   lcd.write(byte(i));
   lcd.setCursor(11,1);
   lcd.write(byte(i));
   lcd.setCursor(12,0);
   lcd.write(byte(i));
   lcd.setCursor(13,1);
   lcd.write(byte(i));
   lcd.setCursor(14,0);
   lcd.write(byte(i));
   lcd.setCursor(15,1);
   lcd.write(byte(i));
   delay(100);
  }  //contracting x
  //Extra Animations can be left to coder's imagination
  //lcd.print("") printing a particular char
  //lcd.blink() blinking cursor on lcd module
  //lcd.noBlink()
  //lcd.cursor(); //underscore cursor
  //lcd.clear() clear lcd screen
}

Schematics

Schematics and Pin Explanation
Brief Ideas about Pins of LCD
Img 20190406 193117 01rxryx90e

Comments

Add projectSign up / Login