-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·64 lines (50 loc) · 1.92 KB
/
main.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
#!/usr/bin/python
import sensor
import lcd
import csv
import time
import os
import datetime
import sys
import re
import circular_buffer
lcd.init()
last_time = datetime.datetime.now()
last_minute = last_time.minute
probe_minute_01 = circular_buffer.CircularBuffer(size=30)
probe_minute_15 = circular_buffer.CircularBuffer(size=15)
probes_minute_30 = circular_buffer.CircularBuffer(size=30)
probes_minute_60 = circular_buffer.CircularBuffer(size=60)
# initialize buffers
current_temperature = sensor.read()
probe_minute_01.append(current_temperature)
probe_minute_15.append(current_temperature)
probes_minute_30.append(current_temperature)
probes_minute_60.append(current_temperature)
while True:
try:
current_time = datetime.datetime.now()
current_minute = current_time.minute
current_temperature = sensor.read()
if current_temperature == 9999:
lcd.top("Temperature")
lcd.bottom("Failed to read")
lcd.cleanup()
sys.exit(0)
probe_minute_01.append(current_temperature)
lcd.top("{:2.1f}".format(current_temperature) + chr(223) + "C " + current_time.strftime("%H:%M:%S"))
if last_minute != current_minute:
lcd.display_init()
probe_minute_15.append(current_temperature)
probes_minute_30.append(current_temperature)
probes_minute_60.append(current_temperature)
csv.append(current_time.strftime("%s") + ";" + str(current_time) + ";" + "{:2.1f}".format(
current_temperature).replace('.', ',') + "\n")
lcd.bottom("{:2.1f}".format(probes_minute_60.average) + chr(223) + " " + "{:2.1f}".format(
probes_minute_30.average) + chr(223) + " " + "{:2.1f}".format(probe_minute_15.average) + chr(223))
time.sleep(2)
last_minute = current_minute
last_time = current_time
except KeyboardInterrupt:
lcd.cleanup()
sys.exit(0)