@@ -76,14 +76,19 @@ class Adafruit_CharLCDPlate(Adafruit_I2C):
7676 # ----------------------------------------------------------------------
7777 # Constructor
7878
79- def __init__ (self , busnum = - 1 , addr = 0x20 , debug = False ):
79+ def __init__ (self , busnum = - 1 , addr = 0x20 , debug = False , backlight = ON ):
8080
8181 self .i2c = Adafruit_I2C (addr , busnum , debug )
8282
8383 # I2C is relatively slow. MCP output port states are cached
8484 # so we don't need to constantly poll-and-change bit states.
8585 self .porta , self .portb , self .ddrb = 0 , 0 , 0b00010000
8686
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+
8792 # Set MCP23017 IOCON register to Bank 0 with sequential operation.
8893 # If chip is already set for Bank 0, this will just write to OLATB,
8994 # which won't seriously bother anything on the plate right now
@@ -116,8 +121,8 @@ def __init__(self, busnum=-1, addr=0x20, debug=False):
116121 0b00000000 , # INTCAPB
117122 self .porta , # GPIOA
118123 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
121126
122127 # Switch to Bank 1 and disable sequential operation.
123128 # From this point forward, the register addresses do NOT match
0 commit comments