-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather-station_alt.py
185 lines (154 loc) · 3.59 KB
/
weather-station_alt.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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import time
import requests
from matrix_lite import gpio
from meteocalc import Temp, dew_point, heat_index
from matrix_lite import led
from matrix_lite import sensors
def temperatureReadout(override):
temperature = sensors.pressure.read().temperature
print(temperature)
temperatureLED = temperature - 7
if (override > 0):
temperatureLED = override
ledSet = []
for x in range(1, int(temperatureLED)):
ledSet.append((25,0,0,0))
led.set(ledSet)
time.sleep(0.1)
led.set(ledSet)
if(temperatureLED > 28):
phoneContact()
led.set('White')
dangerAlert()
time.sleep(5)
# def humidityReadout():
# humidity = sensors.humidity.read().humidity
# print(humidity)
#
# humidityLED = int((humidity / 100) * 35)
#
# if (humidityLED > 34):
# humidityLED = humidityLED / 2
# brightness = 2
# else:
# brightness = 1
# ledSet = []
#
# for x in range(1, int(humidityLED)):
# ledSet.append((0,0,25 * brightness,0))
# led.set(ledSet)
# time.sleep(0.1)
#
# time.sleep(5)
def humidityReadout():
humidity = sensors.humidity.read().humidity
print(humidity)
color = [0,50,255,0]
humidityLED = int((humidity / 100) * 35)
removeLED = 35 - humidityLED
print('remove ' + str(removeLED))
led_list = fade_in([0,50,255,0])
print(led_list)
p = 0
n = 34
while removeLED > 0:
if removeLED > 0:
led_list[p] = 'black'
led.set(led_list)
p += 1
removeLED -= 1
time.sleep(0.05)
if removeLED > 0:
led_list[n] = 'black'
led.set(led_list)
n -= 1
removeLED -= 1
time.sleep(0.05)
time.sleep(4)
removeLED = humidityLED
while removeLED > 0:
if removeLED > 0:
led_list[p] = 'black'
led.set(led_list)
p += 1
removeLED -= 1
time.sleep(0.05)
if removeLED > 0:
led_list[n] = 'black'
led.set(led_list)
n -= 1
removeLED -= 1
time.sleep(0.05)
def heatIndex():
temperatureHI = (sensors.pressure.read().temperature) - 5
humidityHI = sensors.humidity.read().humidity
hi = heat_index(temperature=temperatureHI, humidity= humidityHI)
ledSet = []
for x in range(1, int(hi)):
ledSet.append((25,0,25,0))
led.set(ledSet)
time.sleep(0.1)
if (int(hi) >= 40):
phoneContact()
dangerAlert()
print(hi)
time.sleep(5)
# def heatIndex():
# temperatureHI = (sensors.pressure.read().temperature) - 5
# humidityHI = sensors.humidity.read().humidity
# hi = heat_index(temperature=temperatureHI, humidity= humidityHI)
# min_hi = 0
# max_hi = 30
def phoneContact():
url = 'https://maker.ifttt.com/trigger/call/with/key/br6w0TeQJiNDHpWuKYInm6'
x = requests.post(url, data = 'test')
print("Reached")
def dangerAlert():
while True:
led.set('Red')
time.sleep(.10)
led.set('Black')
time.sleep(.10)
def array_gen(color):
array = []
for n in range(35):
array.append(color)
return array
def fade_in(max_color):
led.set('black')
color = [0,0,0,0]
min_color = [0,0,0,0]
terminate = [0,0,0,0]
delay = 0.0015
while terminate != [1,1,1,1]:
for n in range(4):
if color[n] < max_color[n]:
color[n] += (max_color[n]/255)
else:
terminate[n] = 1
led.set((color[0],color[1],color[2],color[3]))
print(color)
time.sleep(delay)
return array_gen(color)
def fade_out(max_color):
led.set('black')
min_color = [0,0,0,0]
terminate = [0,0,0,0]
terminate = [0,0,0,0]
while terminate != [1,1,1,1]:
for n in range(4):
if color[n] > min_color[n]:
color[n] -= (max_color[n]/255)
else:
terminate[n] = 1
led.set((color[0],color[1],color[2],color[3]))
print(color)
time.sleep(.002)
gpio.setFunction(0, 'DIGITAL')
gpio.setMode(0, "input")
while True:
led.set('Black')
temperatureReadout(0)
humidityReadout()
heatIndex()
led.set('Black')