forked from tdamdouni/Raspberry-Pi-DIY-Projects
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweather_py.py
161 lines (144 loc) · 4.55 KB
/
weather_py.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
# Created by brendan-lewis@hackster
# Once it loads, it logs data to Dropbox
# Designed for a remote weather station
# This code is imperfect, please comment if you have a suggestion
# or something doesn't work and I will try to fix it
import sense_hat, time, dropbox
db = dropbox.Dropbox('MY_ACCESS_TOKEN') # replace MY_ACCESS_TOKEN with your access token
sense = sense_hat.SenseHat()
sense.clear()
R = (255,0,0)
G = (0,255,0)
B = (0,0,255)
W = (255,255,255)
Y = (255,255,0)
P = (255,0,255)
N = (0,0,0)
LOADING_ICONS = [[N,N,N,N,N,N,N,N,
N,N,N,N,N,N,N,N,
N,N,N,N,N,N,N,N,
N,N,N,G,N,N,N,N,
N,N,N,N,N,N,N,N,
N,N,N,N,N,N,N,N,
N,N,N,N,N,N,N,N,
N,N,N,N,N,N,N,N],
[N,N,N,N,N,N,N,N,
N,N,N,N,N,N,N,N,
N,N,N,N,N,N,N,N,
N,N,N,N,G,N,N,N,
N,N,N,N,N,N,N,N,
N,N,N,N,N,N,N,N,
N,N,N,N,N,N,N,N,
N,N,N,N,N,N,N,N],
[N,N,N,N,N,N,N,N,
N,N,N,N,N,N,N,N,
N,N,N,N,N,N,N,N,
N,N,N,N,N,N,N,N,
N,N,N,N,G,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sense.clear()
loading_icn(2, sense)
sense.show_message("Weather Monitor - by brendan-lewis@hackster", scroll_speed = 0.05)
def main():
loading_icn(2,sense)
notDone = True
while notDone:
sense.set_pixels(GREEN_CHECK)
data = str(sense.get_temperature()) + "|"
data = data + str(sense.get_humidity()) + "|"
data = data + str(sense.get_pressure()) + "\n"
db.files_upload(data, "/")
for event in sense.stick.get_events():
notDone = False
if notDone: time.sleep(10) # interval time in seconds
sense.set_pixels(YELLOW_CHECK)
time.sleep(2)
sense.set_pixels(RED_CROSS)
time.sleep(2)
ev = None
notDone = True
while notDone:
sense.show_message("Press", scroll_speed = 0.07)
sense.set_pixels(LEFT_ARROW)
time.sleep(0.7)
sense.show_message("to exit. Press", scroll_speed = 0.07)
sense.set_pixels(RIGHT_ARROW)
time.sleep(0.7)
sense.show_message("to restart.", scroll_speed = 0.07)
for event in sense.stick.get_events():
ev = event
notDone = False
if ev.direction == "right": main()
elif ev.direction == "left":
leave()
def leave():
POWER = [N,W,W,W,W,W,W,N,
W,N,N,W,W,N,N,W,
W,N,N,W,W,N,N,W,
W,N,N,W,W,N,N,W,
W,N,N,W,W,N,N,W,
W,W,N,N,N,N,W,W,
W,N,W,W,W,W,N,W,
N,W,W,W,W,W,W,N]
sense.set_pixels(POWER)
time.sleep(1)
sense.clear()
exit(0)
main()