-
Notifications
You must be signed in to change notification settings - Fork 0
/
two_line_oled.py
69 lines (52 loc) · 1.77 KB
/
two_line_oled.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
# Nice two-line display on the 128x32 OLED display
import board
import displayio
import terminalio
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text import label
import adafruit_displayio_ssd1306
# Our "FreeType-CMU Typewriter Text-Bold-R-Normal" bitmap
FONT_PATH = "fonts/cmuntb22.bdf"
class two_line_oled:
'''Display on an Adafruit 128x64 OLED'''
def __init__(self, i2c_addr, height):
displayio.release_displays()
try:
i2c = board.I2C()
except:
print("Is the I2C wiring correct?")
raise Exception
return
display_bus = displayio.I2CDisplay(i2c, device_address=i2c_addr)
WIDTH = 128
HEIGHT = height
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=WIDTH, height=HEIGHT)
# TODO: check for failure?
font_main = bitmap_font.load_font(FONT_PATH)
text_area_1 = label.Label(font_main, color=0xFFFFFF)
text_area_1.x = 0
text_area_1.y = 12
text_area_2 = label.Label(terminalio.FONT, color=0xFFFFFF)
text_area_2.x = 0
text_area_2.y = 28
root = displayio.Group()
display.root_group = root
root.append(text_area_1)
root.append(text_area_2)
self.text_area_1 = text_area_1
self.text_area_2 = text_area_2
def set_text_1(self, text):
self.text_area_1.text = text
def set_text_2(self, text):
self.text_area_2.text = text
def blank_screen(self):
self.set_text_1("")
self.set_text_2("")
def test():
print(f"\nTesting {__name__}....")
tlo = two_line_oled()
tlo.set_text_1("00:23:34")
tlo.set_text_2("Test-a-roni! How wide?")
print("Test done.")
while True:
pass