-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
88 lines (67 loc) · 1.87 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from rpi_lcd import LCD
from gpiozero import Button
from src.main_menu.get_menu import get_main_menu
from gpiozero import Button, TonalBuzzer, DigitalOutputDevice
from gpiozero.tones import Tone
from time import sleep
from signal import signal, SIGTERM, SIGHUP, pause
import sys, traceback
main_menu = get_main_menu()
main_menu.first_item()
lcd = LCD()
lcd_display_transistor = DigitalOutputDevice(12)
lcd_display_transistor.on()
btn_next = Button(16, pull_up = True, bounce_time = 0.8)
btn_previous = Button(20, pull_up = True, bounce_time = 0.8)
btn_confirm = Button(21, pull_up = True, bounce_time = 0.8)
buzzer = TonalBuzzer(19)
def btn_next_press():
main_menu.next_item()
buzzer.play(Tone(550.0))
sleep(0.1)
buzzer.stop()
sleep(0.2)
def btn_previous_press():
main_menu.previous_item()
buzzer.play(Tone(510.0))
sleep(0.1)
buzzer.stop()
sleep(0.2)
def btn_confirm_press():
main_menu.select_item()
buzzer.play(Tone(590.0))
sleep(0.1)
buzzer.stop()
sleep(0.2)
def hello():
lcd.clear()
sleep(0.6)
lcd.display_enabled = True
lcd.backlight_enabled = True
def goodbye():
lcd.clear()
lcd_display_transistor.off()
sleep(0.6)
lcd.display_enabled = False
lcd.backlight_enabled = False
sys.exit(1)
signal(SIGTERM, goodbye)
signal(SIGHUP, goodbye)
btn_next.when_pressed = btn_next_press
btn_previous.when_pressed = btn_previous_press
btn_confirm.when_pressed = btn_confirm_press
def main():
while True:
lines = main_menu.get_data()
lcd.text(lines[0], 1)
lcd.text(lines[1], 2)
if __name__ == "__main__":
try:
hello()
main()
except KeyboardInterrupt:
print("Stopping due to keyboard iterruption")
except Exception:
print("Stopping due to an unhandled exception")
traceback.print_exc(file=sys.stdout)
goodbye()