Class: I2C::Drivers::SS1602::Display
- Inherits:
-
Object
- Object
- I2C::Drivers::SS1602::Display
- Defined in:
- lib/i2c/drivers/ss1602/display.rb
Overview
Driver class for the SainSmart 1602 I2C LCD Display.
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.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(bus_or_bus_name, device_address) ⇒ 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) ⇒ Display
Returns a new instance of Display.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/i2c/drivers/ss1602/display.rb', line 16 def initialize(bus_or_bus_name, device_address) 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 @rows = 2 @cols = 16 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/ss1602/display.rb', line 14 def cols @cols end |
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
14 15 16 |
# File 'lib/i2c/drivers/ss1602/display.rb', line 14 def cursor @cursor end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
14 15 16 |
# File 'lib/i2c/drivers/ss1602/display.rb', line 14 def rows @rows end |
Instance Method Details
#clear ⇒ Object
31 32 33 34 |
# File 'lib/i2c/drivers/ss1602/display.rb', line 31 def clear write(COMMAND_CLEARDISPLAY) write(COMMAND_RETURNHOME) end |
#off ⇒ Object
58 59 60 |
# File 'lib/i2c/drivers/ss1602/display.rb', line 58 def off write(COMMAND_DISPLAYCONTROL | FLAG_DISPLAYOFF) end |
#on ⇒ Object
54 55 56 |
# File 'lib/i2c/drivers/ss1602/display.rb', line 54 def on write(COMMAND_DISPLAYCONTROL | FLAG_DISPLAYON) end |
#text(string, row, pad = false) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/i2c/drivers/ss1602/display.rb', line 36 def text(string, row, pad = false) case row when 0 write(0x80) when 1 write(0xC0) 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
65 66 67 68 |
# File 'lib/i2c/drivers/ss1602/display.rb', line 65 def write(cmd, mode = 0) write_four_bits(mode | (cmd & 0xF0)) write_four_bits(mode | ((cmd << 4) & 0xF0)) end |