-
Notifications
You must be signed in to change notification settings - Fork 0
/
button_demo.py
47 lines (41 loc) · 906 Bytes
/
button_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import time
import Adafruit_CharLCD as LCD
from threading import Thread
lcd = LCD.Adafruit_CharLCDPlate()
lcd.set_color(0.0, 0.0, 0.0)
def backlight():
lcd.set_color(1.0, 0.0, 0.0)
time.sleep(5)
lcd.set_color(0.0, 0.0, 0.0)
def buttons():
background = Thread(target = backlight)
if lcd.is_pressed(LCD.SELECT):
lcd.clear()
lcd.message('Select')
background.start()
if lcd.is_pressed(LCD.LEFT):
lcd.clear()
lcd.message('Left')
background.start()
if lcd.is_pressed(LCD.RIGHT):
lcd.clear()
lcd.message('Right')
background.start()
if lcd.is_pressed(LCD.UP):
lcd.clear()
lcd.message('Up')
background.start()
if lcd.is_pressed(LCD.DOWN):
lcd.clear()
lcd.message('DOWN')
background.start()
def main_loop():
try:
while True:
buttons()
except KeyboardInterrupt:
lcd.clear()
lcd.set_color(0.0, 0.0, 0.0)
print("\nDone")
if __name__ == "__main__":
main_loop()