Skip to content

Commit c05037f

Browse files
author
Your Name
committed
added basic button handling
1 parent e848301 commit c05037f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ class Adafruit_CharLCD:
2929
ON = 0x07
3030
OFF = 0x0
3131

32+
# buttons
33+
SELECT = 0
34+
RIGHT = 1
35+
DOWN = 2
36+
UP = 3
37+
LEFT = 4
38+
3239
# commands
3340
LCD_CLEARDISPLAY = 0x01
3441
LCD_RETURNHOME = 0x02
@@ -111,6 +118,17 @@ def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, 21, 22], pin_rw=0):
111118
mcp.output(7, 0) # green
112119
mcp.output(8, 0) # blue
113120

121+
# turn on pullups
122+
mcp.pullup(self.SELECT, True)
123+
mcp.pullup(self.LEFT, True)
124+
mcp.pullup(self.RIGHT, True)
125+
mcp.pullup(self.UP, True)
126+
mcp.pullup(self.DOWN, True)
127+
mcp.config(self.SELECT, mcp.INPUT)
128+
mcp.config(self.LEFT, mcp.INPUT)
129+
mcp.config(self.RIGHT, mcp.INPUT)
130+
mcp.config(self.DOWN, mcp.INPUT)
131+
mcp.config(self.UP, mcp.INPUT)
114132

115133
def begin(self, cols, lines):
116134
if (lines > 1):
@@ -250,6 +268,23 @@ def backlight(self, color):
250268
lcd.clear()
251269
lcd.message("Adafruit RGB LCD\nPlate w/Keypad!")
252270
sleep(1)
271+
while 1:
272+
if (not mcp.input(lcd.LEFT)):
273+
lcd.backlight(lcd.RED)
274+
275+
if (not mcp.input(lcd.UP)):
276+
lcd.backlight(lcd.BLUE)
277+
278+
if (not mcp.input(lcd.DOWN)):
279+
lcd.backlight(lcd.GREEN)
280+
281+
if (not mcp.input(lcd.RIGHT)):
282+
lcd.backlight(lcd.VIOLET)
283+
284+
if (not mcp.input(lcd.SELECT)):
285+
lcd.backlight(lcd.ON)
286+
287+
253288
while 1:
254289
lcd.backlight(lcd.RED)
255290
sleep(1)

0 commit comments

Comments
 (0)