Skip to content

Commit 1ec175e

Browse files
committed
add i2c arg to constructor; fix brightness setter
1 parent 19161e4 commit 1ec175e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lcd/i2c_pcf8574_interface.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929

3030

3131
class I2CPCF8574Interface:
32-
32+
3333
# Bit values to turn backlight on/off. Indexed by a boolean.
3434
_BACKLIGHT_VALUES = (LCD_NOBACKLIGHT, LCD_BACKLIGHT)
3535

36-
def __init__(self, address):
36+
def __init__(self, i2c, address):
3737
"""
3838
CharLCD via PCF8574 I2C port expander.
3939
@@ -47,8 +47,8 @@ def __init__(self, address):
4747
self.address = address
4848

4949
self._backlight_pin_state = LCD_BACKLIGHT
50-
51-
self.i2c = busio.I2C(board.SCL, board.SDA)
50+
51+
self.i2c = i2c
5252
self.i2c_device = I2CDevice(self.i2c, self.address)
5353
self.data_buffer = bytearray(1)
5454

@@ -65,8 +65,9 @@ def backlight(self):
6565

6666
@backlight.setter
6767
def backlight(self, value):
68-
self._backlight_pin_state = _BACKLIGHT_VALUES[value]
69-
self._i2c_write(self._backlight_pin_state)
68+
self._backlight_pin_state = self._BACKLIGHT_VALUES[value]
69+
with self.i2c_device:
70+
self._i2c_write(self._backlight_pin_state)
7071

7172
# Low level commands
7273

0 commit comments

Comments
 (0)