Class: I2C::Drivers::LCD::Display
- Inherits:
-
Object
- Object
- I2C::Drivers::LCD::Display
- Defined in:
- lib/i2c/drivers/lcd/display.rb
Overview
Driver class for the 2004/1602 I2C LCD Display.
forked from https://github.com/nerab/i2c-ss1602
see github.com/andec/i2c Parts copied from github.com/paulbarber/raspi-gpio/blob/master/lcd_display.py
Defined Under Namespace
Instance Attribute Summary collapse
-
#cols ⇒ Object
readonly
Returns the value of attribute cols.
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #backlight_off ⇒ Object
- #backlight_on ⇒ Object
- #clear ⇒ Object
-
#initialize(bus_or_bus_name, device_address, cols = 20, rows = 4, dotsize = 8) ⇒ Display
constructor
A new instance of Display.
- #off ⇒ Object
- #on ⇒ Object
- #text(string, row, pad = false) ⇒ Object
-
#write(cmd, mode = 0) ⇒ Object
Send a low-level command to the display.
Constructor Details
#initialize(bus_or_bus_name, device_address, cols = 20, rows = 4, dotsize = 8) ⇒ Display
Returns a new instance of Display.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/i2c/drivers/lcd/display.rb', line 16 def initialize(bus_or_bus_name, device_address, cols=20, rows=4, dotsize=8) if bus_or_bus_name.respond_to?(:write) @device = BusDevice.new(bus_or_bus_name, device_address) else @device = BusDevice.new(I2C.create(bus_or_bus_name), device_address) end @cols = cols @rows = rows @dotsize = dotsize init_sequence @cursor = Cursor.new(self) end |
Instance Attribute Details
#cols ⇒ Object (readonly)
Returns the value of attribute cols.
14 15 16 |
# File 'lib/i2c/drivers/lcd/display.rb', line 14 def cols @cols end |
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
14 15 16 |
# File 'lib/i2c/drivers/lcd/display.rb', line 14 def cursor @cursor end |
#device ⇒ Object (readonly)
Returns the value of attribute device.
14 15 16 |
# File 'lib/i2c/drivers/lcd/display.rb', line 14 def device @device end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
14 15 16 |
# File 'lib/i2c/drivers/lcd/display.rb', line 14 def rows @rows end |
Instance Method Details
#backlight_off ⇒ Object
71 72 73 |
# File 'lib/i2c/drivers/lcd/display.rb', line 71 def backlight_off device.write(FLAG_NOBACKLIGHT) end |
#backlight_on ⇒ Object
67 68 69 |
# File 'lib/i2c/drivers/lcd/display.rb', line 67 def backlight_on device.write(FLAG_BACKLIGHT) end |
#clear ⇒ Object
32 33 34 35 |
# File 'lib/i2c/drivers/lcd/display.rb', line 32 def clear write(COMMAND_CLEARDISPLAY) write(COMMAND_RETURNHOME) end |
#off ⇒ Object
63 64 65 |
# File 'lib/i2c/drivers/lcd/display.rb', line 63 def off write(COMMAND_DISPLAYCONTROL | FLAG_DISPLAYOFF) end |
#on ⇒ Object
59 60 61 |
# File 'lib/i2c/drivers/lcd/display.rb', line 59 def on write(COMMAND_DISPLAYCONTROL | FLAG_DISPLAYON) end |
#text(string, row, pad = false) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/i2c/drivers/lcd/display.rb', line 37 def text(string, row, pad = false) case row when 0 write(LCD_LINE_0) when 1 write(LCD_LINE_1) when 2 write(LCD_LINE_2) when 3 write(LCD_LINE_3) else raise "Only rows #{0..(@rows - 1)} are supported" end # Right-pad with spaces so that the line only shows string string = sprintf('%-1$*2$s', string, @cols) if pad string.each_char do |c| write(c.ord, BIT_RS) end end |
#write(cmd, mode = 0) ⇒ Object
Send a low-level command to the display
78 79 80 81 |
# File 'lib/i2c/drivers/lcd/display.rb', line 78 def write(cmd, mode = 0) write_four_bits(mode | (cmd & 0xF0)) write_four_bits(mode | ((cmd << 4) & 0xF0)) end |