-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.py
69 lines (50 loc) · 2.1 KB
/
weather.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
#!/usr/bin/python
from sense_hat import SenseHat
import time, os, sys
sense = SenseHat()
sense.low_light = True
def getCPUtemperature():
res = os.popen('vcgencmd measure_temp').readline()
return(res.replace("temp=","").replace("'C\n",""))
try:
while True:
now = time.strftime("%S")
if float(now)==0:
sense.clear()
current_time = time.strftime("%H:%M")
print("Current Time",current_time)
cpu_temp = getCPUtemperature()
temp = sense.get_temperature()
temp_p = sense.get_temperature_from_pressure()
temp_cal = float(temp) - (float(cpu_temp)-float(temp))/3.037
temp = round(temp, 1)
cpu_temp = round(float(cpu_temp), 1)
temp_p = round(temp_p, 1)
temp_cal = round(temp_cal, 1)
print("Temperature Sense",temp)
print("Temperature P",temp_p)
print("Temperature CPU",cpu_temp)
print("Temperature Cal",temp_cal)
humidity = sense.get_humidity()
humidity = round(humidity, 1)
print("Humidity RH%",humidity)
pressure = sense.get_pressure()
pressure = round(pressure, 1)
print("Pressure hPa",pressure)
accelerometer_data = sense.get_accelerometer_raw()
x = round(accelerometer_data['x'], 0)
y = round(accelerometer_data['y'], 0)
if y == -1:
sense.set_rotation(180)
elif x == 1:
sense.set_rotation(270)
elif x == -1:
sense.set_rotation(90)
else:
sense.set_rotation(0)
sense.show_message(current_time + " " + str(temp_cal) + "C " + str(humidity) + "% " + str(pressure) + "hPa ", scroll_speed=(0.1), back_colour= [0,0,0], text_colour= [200,0,200])
else:
time.sleep(0.5)
except KeyboardInterrupt:
pass
sense.clear()