-
Notifications
You must be signed in to change notification settings - Fork 0
/
2x16_lcd_output.py
executable file
·55 lines (46 loc) · 1.52 KB
/
2x16_lcd_output.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
#!/bin/python3
# -*- coding: utf-8 -*-
import time, os.path
import RPi_I2C_driver
debug = False
path_to_files = "/tmp/"
mylcd = RPi_I2C_driver.lcd()
mylcd.lcd_clear()
temps = [None] * 3
# Function for printing debug output
def debug_print(text):
if debug:
print(text)
while 1:
try:
with open(path_to_files + 'meteo', 'r') as temps_file:
temps_lines = temps_file.read().splitlines()
for i in range(3):
temps[i] = temps_lines[i]
temps_file.close()
read_fail = 0
debug_print("DEBUG: Read temps file ok")
except: # Write --- (error) if file couldn't be opened
for i in range(3):
temps[i] = u"---"
read_fail = 1
debug_print("DEBUG: Read temps file failed")
if read_fail:
mylcd.lcd_clear()
mylcd.lcd_display_string("Chyba cteni", 1)
else:
if temps[0] != None:
if temps[0] != u"---" and temps[1]!= u"---":
if float(temps[1]) - float(temps[0]) >= 0:
mylcd.lcd_display_string("Voda: " + str(round(float(temps[0]), 1)) + "+" + str(round(float(temps[1]) - float(temps[0]), 1)) + u"\337" + "C", 1)
else:
mylcd.lcd_display_string("Voda: " + str(round(float(temps[0]), 1)) + "-" + str(abs(round(float(temps[1]) - float(temps[0]), 1))) + u"\337" + "C", 1)
else:
mylcd.lcd_display_string_pos(" ", 1, 9)
mylcd.lcd_display_string("Voda: ---", 1)
if temps[2] != u"---":
mylcd.lcd_display_string("Vzduch: " + str(round(float(temps[2]), 1)) + u"\337" + "C ", 2)
else:
mylcd.lcd_display_string_pos(" ", 2, 11)
mylcd.lcd_display_string("Vzduch: ---", 2)
time.sleep(5)