Human Interfacing

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 25

Human-Machine

Interfacing
Libraries

 The Arduino environment can be extended through the


use of libraries, just like most programming platforms.
 Libraries provide extra functionality for use in sketches,
e.g. working with hardware or manipulating data
LCD Module
LCD Pin Assignment
LCD Module Arduino Uno
5V 5V
GND GND
Data bit 7 2
Data bit 6 3
Data bit 5 4
Data bit 4 5
EN 11
RS 12
R/W GND
LCD Pinouts
LCD Library

 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

 Specify print dimensions


name.begin(cols, rows)
 name = variable name for the LCD, must match from
initialization
 cols = number of columns, e.g. 16 for a 16x2 display
 rows = number of rows, e.g. 2 for a 16x2 display
LCD Library
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
Void setup(){
lcd.begin(16,2);
}

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

 getKey() - returns the key that is pressed, if any


 getState() - returns the current state of any of the keys
(IDLE, PRESSED, RELEASED and HOLD)
 addEventListener(keypadEvent) – calls the function
specified by keypadEvent whenever the keypad is
used/pressed
 begin(makeKeymap(userKeymap)) – initializes a
declared keymap to be used by the routine, used to
enable multi-mapped keys (i.e. in cellphones)
Keypad Library
 setHoldTime(unsigned int time) - amount of milliseconds
needed to trigger HOLD state.
 setDebounceTime(unsigned int time) - amount of
milliseconds to wait until it accepts a new
keypress/keyEvent
 EventKeypad sample sketch shows how to handle
keypad press and state events, enabling additional
hardware interaction
 DynamicKeypad sample sketch shows how to use
multiple keymaps on a single keypad device, adding
more functionality

You might also like