-
Notifications
You must be signed in to change notification settings - Fork 0
/
enviropi.py
74 lines (64 loc) · 2.03 KB
/
enviropi.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
#!/usr/bin/env python
# Compass in progress, commands involve:
# north = motion.heading(), print(motion.heading()),
# corr_heading = (motion.heading() - north) % 360
# Referenced @
# https://learn.pimoroni.com/tutorial/sandyj/getting-started-with-enviro-phat
import time
from envirophat import light, motion, weather, leds
print("""Light the LEDs upon temperature increase.
Press Ctrl+C to exit.
""")
threshold = None
try:
while True:
north = motion.heading()
corr_heading = (motion.heading() - north) % 360
temperature = weather.temperature()
fahrenheit = (temperature * 9/5) + 32
barometric = weather.pressure()
InHg = (barometric / 3386.39)
if threshold is None:
threshold = temperature + 2
if corr_heading is 345 - 360 or 0 - 15:
print ("N")
if corr_heading is 16 - 29:
print ("NNE")
if corr_heading is 30 - 60:
print ("NE")
if corr_heading is 61 - 74:
print ("ENE")
if corr_heading is 75 - 105:
print ("E")
if corr_heading is 106 - 119:
print ("ESE")
if corr_heading is 120 - 150:
print ("SE")
if corr_heading is 151 - 164:
print ("SSE")
if corr_heading is 165 - 195:
print ("S")
if corr_heading is 196 - 209:
print ("SSW")
if corr_heading is 210 - 240:
print ("SW")
if corr_heading is 241 - 254:
print ("WSW")
if corr_heading is 255 - 285:
print ("W")
if corr_heading is 286 - 299:
print ("WNW")
if corr_heading is 300 - 330:
print ("NW")
if corr_heading is 331 - 344:
print ("NNW")
print(corr_heading)
print("{0:.1f} F".format(fahrenheit))
print("{0:.3f} InHg".format(InHg))
if temperature > threshold:
leds.on()
else:
leds.off()
time.sleep(3)
except KeyboardInterrupt:
pass