Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Commit 349fbb2

Browse files
committed
Resolve #65 by adding optional backlight parameter which defaults on to init function.
1 parent d3ff417 commit 349fbb2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)