-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
154 lines (100 loc) · 3.84 KB
/
main.py
File metadata and controls
154 lines (100 loc) · 3.84 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#D2 - button, D3 - Servo, D4 - Blue Light, D8 - Buzzer, D6 - Touch, I2C - LCD, A0 - Temp Sensor
from homepy.arduino import *
import threading
from time import sleep
notif = []
actionInput = 0
desTempGlobal = 0
lockThreads = threading.Lock()
def doorBell():
while True:
if digital_read(2) == True:
buzzer_note(8,20,500)
if "Answer the door" not in notif:
with lockThreads:
notif.append("Answer the door")
return
def tempControl():
while True:
if temp_celsius(0) > (desTempGlobal + 0.5):
lcd_clear()
lcd_rgb(0,150,0)
lcd_print(round(temp_celsius(0),2))
digital_write(4,1) #Blue Light ON
elif temp_celsius(0) < (desTempGlobal - 0.5):
lcd_rgb(255,0,0) #Red LCD Background
lcd_clear()
lcd_print("Heaters ON-"+str(round(temp_celsius(0),2)))
digital_write(4,0) #Blue Light OFF
else:
digital_write(4,0) #Blue Light OFF
lcd_clear()
lcd_rgb(0,150,0)
lcd_print(round(temp_celsius(0),2))
sleep(0.5)
return
def IRsensor():
while True:
if digital_read(6) == True: #Touch Sensor for now
buzzer_note(8,20,30000)
if "Proximity Danger" not in notif:
with lockThreads:
notif.append("Proximity Danger")
return
def mainMenu():
print("\n\n\nWelcome to the Smart Home Control Window")
print("-----Main Menu-----")
print("1. Change the Desired Temperature\n2. Show notifications")
return
def setDesTemp():
global desTempGlobal #Declaring global as to change the value of this globally declared variable
desTempGlobal = float(input("Enter your Desired Temperature in Celsius - "))
print("\nSettings applied!\nYou will be redirected to the Main Menu in 3 seconds....")
sleep(3)
return
#Creating Processes
doorFunc = threading.Thread(target=doorBell)
IRFunc = threading.Thread(target=IRsensor)
desTempGlobal = float(input("\nEnter your Desired Temperature in Celsius - "))
tempFunc = threading.Thread(target=tempControl)
#Starting Processes
doorFunc.start()
IRFunc.start()
tempFunc.start()
#HomeScreen
while True:
mainMenu()
actionInput = input("\nChoose from the above options - ")
if actionInput == '':
continue
actionInput = int(actionInput)
if actionInput == 1:
setDesTemp()
elif actionInput == 2:
if len(notif) == 0:
print("\n\n0 notifications\nYou will be redirected to the Main Menu")
else:
for num,item in enumerate(notif,1):
print(num,item)
notifInput = input("\nChoose from the above notifications to respond or press 3 to remove all- ")
if notifInput == '':
continue
notifInput = int(notifInput)
if 1 <= notifInput <= 2:
if notif[notifInput-1] == "Answer the door":
servo_move(3,180) #Opens the door
with lockthreads:
notif.remove("Answer the door")
sleep(5) #Waits for 5 seconds
servo_move(3,0) #Closes the door
elif notif[notifInput-1] == "Proximity Danger":
with lockthreads:
notif.remove("Proximity Danger")
buzzer_stop(8)
elif notifInput == 3: #Clears the notifications list
with lockthreads:
notif.clear()
buzzer.stop(8)
elif actionInput == 9: #Program kill value
print("Program Terminated")
break