File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change 29
29
30
30
31
31
class I2CPCF8574Interface :
32
-
32
+
33
33
# Bit values to turn backlight on/off. Indexed by a boolean.
34
34
_BACKLIGHT_VALUES = (LCD_NOBACKLIGHT , LCD_BACKLIGHT )
35
35
36
- def __init__ (self , address ):
36
+ def __init__ (self , i2c , address ):
37
37
"""
38
38
CharLCD via PCF8574 I2C port expander.
39
39
@@ -47,8 +47,8 @@ def __init__(self, address):
47
47
self .address = address
48
48
49
49
self ._backlight_pin_state = LCD_BACKLIGHT
50
-
51
- self .i2c = busio . I2C ( board . SCL , board . SDA )
50
+
51
+ self .i2c = i2c
52
52
self .i2c_device = I2CDevice (self .i2c , self .address )
53
53
self .data_buffer = bytearray (1 )
54
54
@@ -65,8 +65,9 @@ def backlight(self):
65
65
66
66
@backlight .setter
67
67
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 )
70
71
71
72
# Low level commands
72
73
You can’t perform that action at this time.
0 commit comments