-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.py
executable file
·70 lines (59 loc) · 1.86 KB
/
display.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/env python
# coding=utf-8
# Bibliotheken importieren
from lib_oled96 import ssd1306
from smbus import SMBus
from PIL import ImageFont
import time
class display():
def __init__(self):
self.draw = 0
self.fontBig = 0
self.fontSmall = 0
self.oled = 0
self.number = 333
self.update = False
self.init()
def init(self):
# Display einrichten
i2cbus = SMBus(1) # 0 = Raspberry Pi 1, 1 = Raspberry Pi > 1
self.oled = ssd1306(i2cbus)
# Ein paar Abkürzungen, um den Code zu entschlacken
self.draw = self.oled.canvas
# Schriftarten festlegen
self.fontSmall = ImageFont.truetype('FreeSans.ttf', 13)
self.fontBig = ImageFont.truetype('FreeSans.ttf', 55)
# Display zum Start löschen
self.oled.cls()
self.oled.display()
def drawer(self, bg):
self.draw.text((0, 0), "Measurement Number:", font=self.fontSmall, fill=1)
if (bg):
self.draw.rectangle((0, 13, 128, 64), outline=1, fill=1)
self.draw.text((0, 10), str(self.number), font=self.fontBig, fill=0)
else :
self.draw.rectangle((0, 13, 128, 64), outline=0, fill=0)
self.draw.text((0, 10), str(self.number), font=self.fontBig, fill=1)
# Ausgaben auf Display schreiben
self.oled.display()
def start(self):
self.update = 1
def stop(self):
self.update = 0
def work(self):
if (self.update):
self.drawer(True)
else:
self.drawer(False)
def worker(self):
delay = 1
while True:
if (self.update):
self.drawer(True)
time.sleep(delay)
self.drawer(False)
time.sleep(delay)
#iface = Display()
#iface.number = 666
#iface.update = True
#iface.worker()