Professional Documents
Culture Documents
Human Interfacing
Human Interfacing
Human Interfacing
Interfacing
Libraries
Arduino has standard libraries which provide extra functionality for use in
sketches.
The LiquidCrystal library allows an Arduino to control LCDs based in the
HD44780 chipset.
To use the LiquidCrystal library in a sketch:
Sketch -> Import Library -> LiquidCrystal
LCD Library
#include<LiquidCrystal.h>
Void setup(){
}
Void loop(){
}
LCD Library
Initialize the LCD LiquidCrystal name(rs, rw, en, d0, d1, d2, d3, d4, d5, d6, d7)
name = variable name for the LCD
Values inside the parenthesis are all pin number labels.
LCD Library
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
Void setup(){
}
Void loop(){
}
LCD Library
Void loop(){
}
LCD Library
Display data
name.print(data)
name = variable name for the LCD, must match from
initialization
data = data to print
LCD Library
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
Void setup(){
lcd.begin(16,2);
lcd.print(“hello world!”);
}
Void loop(){
}
LCD Library
Set the display cursor
name.setCursor(column, line)
name = variable name for the LCD, must match from
initialization
column = 0 to 15
line = 0 or 1
LCD Library
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
Void setup(){
lcd.begin(16,2);
lcd.print(“hello world!”);
lcd.setCUrsor(0,1);
lcd.print(“hi!”);
}
Void loop(){
}
LCD Library
Has many more specified instructions
clear() – clears the whole display
home() – places the cursor at the upper left corner (0,0)
cursor(), blink(), display() – control device behavior during
standby
scrollDisplayLeft() and scrollDisplayRight() – moves the
display one space to the left/right
autoscroll() – automatically scrolls incoming text based on
text direction
leftToRight() and rightToLeft() – control text direction
Keypad
A series of switches that are systematically arranged to
be able to provide a range of data depending on their
combined states
4x3 keypad – common arrangement used for keypads
Membrane format keypads are popular in installation
fixtures for its minimalist design and structure
Keypad Scanning
Columns – INPUT Rows –
OUTPUT
Scan begins by driving one row
LOW and all the others HIGH
All inputs (columns) will then be
read one by one
Keypad Scanning
If no button was pressed, all
reads are expected to return a
HIGH state
At this point, the routine will
drive the next row LOW, and
repeat the whole process
Keypad Scanning
If a button was pressed,
once the row it belongs to is
driven LOW, a LOW is
returned when the column it
belongs to is read
This matrix method enables
us to know which button on
the keypad is pressed
Keypad Scanning
This implementation is BLOCKING – the routine requires
continuous scanning!
Blocking Code – routines that stall the main code
sequence/progression
Take note that the buttons are momentary, adding latch
behavior will considerably complicate your code
To help simplify things, use the Keypad library!
Keypad Library
Connect ROW lines to pins
A0 to A3, and COLUMN lines
to pins 8 to 10 (from left to
right)
Recall: Analog Input pins
can be used as Digital Pins
as well (A0 to A5 = DIO 14 to
19)
Keypad Library
Open HelloKeypad sketch from the Libraries example,
change the pins used with respect to the new
assignments
Upload the code, then open the Serial Monitor to view
output
CHALLENGE! – Print the output on the LCD Display! When
top row full automatically proceed to the bottom row,
when all full clear and reset display
CLUE: Need a counter for row and column!
Keypad Library