@@ -76,14 +76,19 @@ class Adafruit_CharLCDPlate(Adafruit_I2C):
76
76
# ----------------------------------------------------------------------
77
77
# Constructor
78
78
79
- def __init__ (self , busnum = - 1 , addr = 0x20 , debug = False ):
79
+ def __init__ (self , busnum = - 1 , addr = 0x20 , debug = False , backlight = ON ):
80
80
81
81
self .i2c = Adafruit_I2C (addr , busnum , debug )
82
82
83
83
# I2C is relatively slow. MCP output port states are cached
84
84
# so we don't need to constantly poll-and-change bit states.
85
85
self .porta , self .portb , self .ddrb = 0 , 0 , 0b00010000
86
86
87
+ # Set initial backlight color.
88
+ c = ~ backlight
89
+ self .porta = (self .porta & 0b00111111 ) | ((c & 0b011 ) << 6 )
90
+ self .portb = (self .portb & 0b11111110 ) | ((c & 0b100 ) >> 2 )
91
+
87
92
# Set MCP23017 IOCON register to Bank 0 with sequential operation.
88
93
# If chip is already set for Bank 0, this will just write to OLATB,
89
94
# which won't seriously bother anything on the plate right now
@@ -116,8 +121,8 @@ def __init__(self, busnum=-1, addr=0x20, debug=False):
116
121
0b00000000 , # INTCAPB
117
122
self .porta , # GPIOA
118
123
self .portb , # GPIOB
119
- self .porta , # OLATA 0 on all outputs; side effect of
120
- self .portb ]) # OLATB turning on R+G+B backlight LEDs.
124
+ self .porta , # OLATA
125
+ self .portb ]) # OLATB
121
126
122
127
# Switch to Bank 1 and disable sequential operation.
123
128
# From this point forward, the register addresses do NOT match
0 commit comments