@@ -29,6 +29,13 @@ class Adafruit_CharLCD:
29
29
ON = 0x07
30
30
OFF = 0x0
31
31
32
+ # buttons
33
+ SELECT = 0
34
+ RIGHT = 1
35
+ DOWN = 2
36
+ UP = 3
37
+ LEFT = 4
38
+
32
39
# commands
33
40
LCD_CLEARDISPLAY = 0x01
34
41
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):
111
118
mcp .output (7 , 0 ) # green
112
119
mcp .output (8 , 0 ) # blue
113
120
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 )
114
132
115
133
def begin (self , cols , lines ):
116
134
if (lines > 1 ):
@@ -250,6 +268,23 @@ def backlight(self, color):
250
268
lcd .clear ()
251
269
lcd .message ("Adafruit RGB LCD\n Plate w/Keypad!" )
252
270
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
+
253
288
while 1 :
254
289
lcd .backlight (lcd .RED )
255
290
sleep (1 )
0 commit comments