class I2CDevice::HD44780
I2C interface with HD44780
compatible commands
Constants
- MAP
Public Class Methods
new(args={})
click to toggle source
Calls superclass method
I2CDevice::new
# File lib/templates/grove_pi/i2c/device/hd44780.rb, line 18 def initialize(args={}) super @lines = [] initialize_lcd end
Public Instance Methods
clear_display()
click to toggle source
# File lib/templates/grove_pi/i2c/device/hd44780.rb, line 85 def clear_display @lines.clear i2cset(0, 0b00000001) sleep 2.16e-3 end
Also aliased as: clear
cursor_or_display_shift(s_c, r_l)
click to toggle source
s_c
- Integer
-
Cursor or display
- 0
-
Cursor shift
- 1
-
Display shift
r_l
- Integer
-
Direction
- 0
-
Left
- 1
-
Right
# File lib/templates/grove_pi/i2c/device/hd44780.rb, line 129 def cursor_or_display_shift(s_c, r_l) i2cset(0, 0b00010000 | (s_c<<3) | (r_l<<2)) sleep 60e-6 end
define_character(n, array)
click to toggle source
n
- Integer
-
Character code.
array
- Array
-
Character data.
Usage:
lcd.define_character(0, [ 0,1,1,1,0, 1,0,0,0,1, 1,1,0,1,1, 1,0,1,0,1, 1,1,0,1,1, 1,0,0,0,1, 1,0,0,0,1, 0,1,1,1,0, ])
# File lib/templates/grove_pi/i2c/device/hd44780.rb, line 72 def define_character(n, array) raise "n < 8" unless n < 8 raise "array size must be 40 (5x8)" unless array.size == 40 array = array.each_slice(5).map {|i| i.inject {|r,i| (r << 1) + i } } set_cgram_address(8 * n) sleep 60e-6 i2cset(*array.map {|i| [0x80, i] }.flatten) sleep 60e-6 end
display_on_off_control(d, c, b)
click to toggle source
d
- Integer
-
Set entire display on/off
- 0
-
Off
- 1
-
On
c
- Integer
-
Cursor on/off
- 0
-
Off
- 1
-
On
b
- Integer
-
Blink cursor
- 0
-
Off
- 1
-
On
# File lib/templates/grove_pi/i2c/device/hd44780.rb, line 118 def display_on_off_control(d, c, b) i2cset(0, 0b00001000 | (d<<2) | (c<<1) | (b)) sleep 60e-6 end
entry_mode_set(i_d, s)
click to toggle source
i_d
- Integer
-
Increment or decrement
- 0
-
Decrement
- 1
-
Increment
s
- Integer
-
Shift entire display
- 0
-
Right
- 1
-
Left
# File lib/templates/grove_pi/i2c/device/hd44780.rb, line 104 def entry_mode_set(i_d, s) i2cset(0, 0b00000100 | (i_d<<1) | (s)) sleep 60e-6 end
function_set(dl, n, f)
click to toggle source
dl
- Integer
-
Data length
- 0
-
4bit
- 1
-
8bit
n
- Integer
-
Number of display lines
- 0
-
1-line
- 1
-
2-line
f
- Integer
-
Character font
- 0
-
Normal
- 1
-
Double font
# File lib/templates/grove_pi/i2c/device/hd44780.rb, line 143 def function_set(dl, n, f) i2cset(0, 0b00100000 | (dl<<4) | (n<<3) | (f<<2)) sleep 60e-6 end
initialize_lcd()
click to toggle source
Initialize LCD controller sequence Display is cleared.
# File lib/templates/grove_pi/i2c/device/hd44780.rb, line 26 def initialize_lcd function_set(1, 1, 0) sleep 4.1e-3 function_set(1, 1, 0) sleep 100e-6 function_set(1, 1, 0) function_set(1, 1, 0) display_on_off_control(1, 0, 0) clear end
put_line(line, str, force=false)
click to toggle source
line
- Integer
-
Line number
str
- String
-
Display string
force
- true | false
-
Write data forcely.
Note: This method keep previous put_line
strings and does not write without change. You must specify force to override this behaviour.
# File lib/templates/grove_pi/i2c/device/hd44780.rb, line 43 def put_line(line, str, force=false) str.force_encoding(Encoding::BINARY) str.gsub!(/#{MAP.keys.join('|')}/, MAP) str = "%- 16s" % str if force || str != @lines[line] # set ddram address set_ddram_address(0x40 * line) sleep 60e-6 i2cset(*str.unpack("C*").map {|i| [0x80, i] }.flatten) sleep 60e-6 end @lines[line] = str end
read_busy_flag_and_address()
click to toggle source
Returns
- Hash
-
Result
- :busy
- true | false
-
Busy flag
- :address_counter
- Integer
-
Current address count. 7-bit
# File lib/templates/grove_pi/i2c/device/hd44780.rb, line 165 def read_busy_flag_and_address read = i2cget(0b01000000) { :busy => (read & 0b10000000) != 0, :address_counter => read & 0b01111111 } end
return_home()
click to toggle source
# File lib/templates/grove_pi/i2c/device/hd44780.rb, line 93 def return_home i2cset(0, 0b00000010) sleep 1.52e-3 end
set_cgram_address(address)
click to toggle source
address
- Integer
-
CGRAM address 6-bit
# File lib/templates/grove_pi/i2c/device/hd44780.rb, line 149 def set_cgram_address(address) address = address & 0b00111111 i2cset(0, 0b01000000 | address) sleep 60e-6 end
set_ddram_address(address)
click to toggle source
address
- Integer
-
DDRAM address 7-bit
# File lib/templates/grove_pi/i2c/device/hd44780.rb, line 156 def set_ddram_address(address) address = address & 0b01111111 i2cset(0, 0b10000000 | address) sleep 60e-6 end