-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathLCD3.py
67 lines (58 loc) · 1.75 KB
/
LCD3.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
#!/usr/bin/python
import urllib2
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate
from gpiozero import Button
from Ringer import FamilyOrFriend, Salesman, Deliverer, HansOrGrietje
from RingerSingleButton import SingleButton
EMAIL = '[email protected]; [email protected]'
b7red = Button(7)
# Set 4 doorbell-buttons connected to GPIO's 16, 18, 19 & 20, while 17 is connected to Ground
b21blue = Button(21)
b20yellow = Button(20)
b16green = Button(16)
b12white = Button(12)
# Initialize the LCD plate.
try:
lcd = Adafruit_CharLCDPlate()
lcd.clear()
lcdIsOperational = True
except:
lcdIsOperational = False
if lcdIsOperational: # Clear display and show greeting, pause 1 sec
lcd.clear()
lcd.backlight(lcd.ON)
lcd.message("Welcome to your\ndoorbell")
def internet_on():
try:
urllib2.urlopen('http://www.google.com', timeout=10)
return True
except urllib2.URLError:
pass
return False
# lcd.clear()
if internet_on():
print('Internet is up')
# lcd.message("Internet is set\nup :)")
else:
print('Internet is down')
# lcd.message("No internet use\nDoorbell wifi")
while True:
doorbell_pressed = False
while not doorbell_pressed:
if b21blue.is_pressed:
ringer = FamilyOrFriend()
doorbell_pressed = True
if b20yellow.is_pressed:
ringer = Salesman()
doorbell_pressed = True
if b16green.is_pressed:
ringer = Deliverer()
doorbell_pressed = True
if b12white.is_pressed:
ringer = HansOrGrietje()
doorbell_pressed = True
if b7red.is_pressed:
ringer = SingleButton()
doorbell_pressed = True
if doorbell_pressed:
ringer.respond()