PWM LCD 7segment
PWM LCD 7segment
Topics:
The Arduino
Digital IO
Analog IO
Serial Communication
Digital v/s Analog (Cont..)
•Microcontrollers are digital devices – ON or OFF. Also
called – discrete.
•analog signals are anything that can be a full range of
values. What are some examples? More on this later…
5V 5V
0V 0V
Digital v/s Analog & PWM
• A few (digital) pins (3,5,6,9,10,11) on the Arduino allow for us to
modify the output to mimic an analog signal.
• This is done by a technique called: Pulse Width Modulation (PWM).
• To create an analog signal, the microcontroller uses a technique
called PWM. By varying the duty cycle, we can mimic an “average”
analog voltage.
analogWrite(pin, val);
Eg. analogWrite(3, 0-255);
for(int i=6;i<13;i++)
{
digitalWrite(i, LOW);
delay(600);
}
// loop to turn leds od seven seg OFF
for(int i=6;i<13;i++)
{
digitalWrite(i, HIGH);
delay(600);
}
delay(1000);
}
Seven Segment
Common Cathode Seven Segment
What will be the hex vaue to display eight
with dot on Seven segment using Common
annode Seven Segment?
• A) 7F
• B) FF
• C) 00
• D) 4F
Code
Driving Multi-digit 7-segment LEDs
• You want to display numbers using a 7-segment
display that shows two or more digits.
Liquid Crystal Display (LCD)
• Liquid crystal displays (LCDs) offer a
convenient and inexpensive way to provide a
user interface for a project.
4bit mode
4bit mode
LCD Interfacing
LCD pin details
Header files
#include <LiquidCrystal.h>
Description
Initializes the interface to the LCD screen, and specifies the dimensions (width
and height) of the display. begin()needs to be called before any other LCD
library commands.
Syntax
lcd.begin(cols, rows)
Parameters
lcd: a variable of type LiquidCrystal
cols: the number of columns that the display has
rows: the number of rows that the display has
setCursor()
Description
Position the LCD cursor; that is, set the location at which subsequent text
written to the LCD will be displayed.
Syntax
lcd.setCursor(col, row)
Parameters
lcd: a variable of type LiquidCrystal
col: the column at which to position the cursor (with 0 being the first column)
row: the row at which to position the cursor (with 0 being the first row)
write()
Description
Write a character to the LCD.
Syntax
lcd.write(data)
Parameters
lcd: a variable of type LiquidCrystal
data: the character to write to the display
print()
Description
Prints text to the LCD.
Syntax
lcd.print(data)
lcd.print(data, BASE)
Parameters
lcd: a variable of type LiquidCrystal
BASE (optional): the base in which to print numbers: BIN for binary (base 2),
DEC for decimal (base 10), OCT for octal (base 8), HEX for hexadecimal
(base 16).
cursor() noCursor()
Description:
Display the LCD cursor an Description
underscore (line) at the position to Hides the LCD cursor.
which the next character will be
written.
Syntax
lcd.cursor()
Syntax
lcd.noCursor()
noDisplay() display()
Description Description
Turns off the LCD display, without Turns on the LCD display, after it's been
losing the text currently shown on it. turned off with noDisplay(). This will
restore the text (and cursor) that was on
the display.
Syntax
Syntax
lcd.display()
lcd.noDisplay()
setCursor()
Description
Position the LCD cursor; that is, set the location at which subsequent text written to
the LCD will be displayed.
Syntax
lcd.setCursor(col, row)
Parameters
lcd: a variable of type LiquidCrystal
col: the column at which to position the cursor (with 0 being the first column)
row: the row at which to position the cursor (with 0 being the first row)
scrollDisplayLeft() scrollDisplayRight()
Description Description
Scrolls the contents of Scrolls the contents of
the display (text and the display (text and
cursor) one space to the cursor) one space to the
left. right.
Syntax Syntax
lcd.scrollDisplayLeft() lcd.scrollDisplayRight()
leftToRight() rightToLeft()
Description Description
Set the direction for text written to the
Set the direction for text written to the
LCD to right-to-left (the default is left-
LCD to left-to-right, the default. This to-right). This means that subsequent
means that subsequent characters characters written to the display will
written to the display will go from left go from right to left, but does not
to right, but does not affect affect previously-output text.
previously-output text.
Syntax
Syntax lcd.rightToLeft()
lcd.leftToRight()
clear()
Description
Clears the LCD screen and positions the cursor in the
upper-left corner.
Syntax
lcd.clear()
Parameters
lcd: a variable of type LiquidCrystal
Which lcd function help to clear
the data from its screen only?
• A) clear()
• B) clearit()
• C) display()
• D) noDisplay()
Example 1- Still Message Display On
LCD
// include the library code:
#include <LiquidCrystal.h>
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
void loop()
{
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins
with 0):
lcd.setCursor(0,1);
delay(250);
}
Arduino sketch
#include <LiquidCrystal.h>
void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}
void loop()
{
// set the cursor to (0,0):
lcd.setCursor(0, 0);
lcd.createChar(0, customChar);
lcd.begin(16, 2);
lcd.write((byte(0));
}
void loop()
{
}
WAP to display hello and bye on LCD received from HC05
WAP to display smiles as temperature is increasing and
decreasing.
• map(x,0,1023,0,255)