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

Commit 86670a0

Browse files
author
Your Name
committed
fixed up buttonPrssed() function - much nicer now!
1 parent 12b02c0 commit 86670a0

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ def backlight(self, color):
252252
mcp.output(7, not color & 0x02)
253253
mcp.output(8, not color & 0x04)
254254

255+
def buttonPressed(self, buttonname):
256+
if (buttonname > self.LEFT):
257+
return false
258+
259+
return not mcp.input(buttonname)
260+
255261

256262
if __name__ == '__main__':
257263

@@ -268,19 +274,19 @@ def backlight(self, color):
268274
lcd.message("Adafruit RGB LCD\nPlate w/Keypad!")
269275
sleep(1)
270276
while 1:
271-
if (not mcp.input(lcd.LEFT)):
277+
if (lcd.buttonPressed(lcd.LEFT)):
272278
lcd.backlight(lcd.RED)
273279

274-
if (not mcp.input(lcd.UP)):
280+
if (lcd.buttonPressed(lcd.UP)):
275281
lcd.backlight(lcd.BLUE)
276282

277-
if (not mcp.input(lcd.DOWN)):
283+
if (lcd.buttonPressed(lcd.DOWN)):
278284
lcd.backlight(lcd.GREEN)
279285

280-
if (not mcp.input(lcd.RIGHT)):
286+
if (lcd.buttonPressed(lcd.RIGHT)):
281287
lcd.backlight(lcd.VIOLET)
282288

283-
if (not mcp.input(lcd.SELECT)):
289+
if (lcd.buttonPressed(lcd.SELECT)):
284290
lcd.backlight(lcd.ON)
285291

286292

0 commit comments

Comments
 (0)