Skip to content

Add I2C address parameter #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions adafruit_character_lcd/character_lcd_i2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@


class Character_LCD_I2C(Character_LCD_Mono):
# pylint: disable=too-few-public-methods
# pylint: disable=too-few-public-methods, too-many-arguments
"""Character LCD connected to I2C/SPI backpack using its I2C connection.
This is a subclass of Character_LCD and implements all of the same
functions and functionality.
Expand All @@ -66,13 +66,16 @@ class Character_LCD_I2C(Character_LCD_Mono):
i2c = busio.I2C(board.SCL, board.SDA)
lcd = Character_LCD_I2C(i2c, 16, 2)
"""
def __init__(self, i2c, columns, lines, backlight_inverted=False):
def __init__(self, i2c, columns, lines, address=None, backlight_inverted=False):
"""Initialize character LCD connected to backpack using I2C connection
on the specified I2C bus with the specified number of columns and
lines on the display. Optionally specify if backlight is inverted.
"""
from adafruit_mcp230xx.mcp23008 import MCP23008
mcp = MCP23008(i2c)
if address:
mcp = MCP23008(i2c, address=address)
else:
mcp = MCP23008(i2c)
super().__init__(mcp.get_pin(1),
mcp.get_pin(2),
mcp.get_pin(3),
Expand Down
7 changes: 5 additions & 2 deletions adafruit_character_lcd/character_lcd_rgb_i2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,17 @@ class Character_LCD_RGB_I2C(Character_LCD_RGB):
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)

"""
def __init__(self, i2c, columns, lines):
def __init__(self, i2c, columns, lines, address=None):
# pylint: disable=too-many-locals
"""Initialize RGB character LCD connected to shield using I2C connection
on the specified I2C bus with the specified number of columns and lines
on the display.
"""
from adafruit_mcp230xx.mcp23017 import MCP23017
mcp = MCP23017(i2c)
if address:
mcp = MCP23017(i2c, address=address)
else:
mcp = MCP23017(i2c)

self._left_button = mcp.get_pin(4)
self._up_button = mcp.get_pin(3)
Expand Down