-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcd.py
32 lines (27 loc) · 767 Bytes
/
lcd.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
#!/usr/bin/env python
import smbus
from time import sleep, strftime
from datetime import datetime
from RPLCD.i2c import CharLCD # sudo pip install RPLCD
lcd1602 = CharLCD('PCF8574',0x27)
def get_cpu_temp():
# CPU Temperatur aus Datei lesen "/sys/class/thermal/thermal_zone0/temp"
tmp = open('/sys/class/thermal/thermal_zone0/temp')
cpu = tmp.read()
tmp.close()
return 'CPU: ' + '{:.2f}'.format( float(cpu)/1000 ) + ' C '
def get_time_now():
# get system time
return datetime.now().strftime('%H:%M')
def destroy():
lcd1602.clear()
try:
while(True):
lcd1602.clear()
lcd1602.cursor_pos = (0,0)
lcd1602.write_string(get_cpu_temp() )
lcd1602.cursor_pos = (1,0)
lcd1602.write_string(get_time_now() )
sleep(10)
except KeyboardInterrupt:
destroy()