-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholed_display.py
94 lines (63 loc) · 2.34 KB
/
oled_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import board
import displayio
from displayio import I2CDisplay as I2CDisplayBus
import terminalio
from adafruit_display_text import label
import adafruit_displayio_ssd1306
import time
class oled_display:
def __init__(self):
print("Creating oled_display...")
displayio.release_displays()
i2c = board.I2C() # uses board.SCL and board.SDA
display_bus = I2CDisplayBus(i2c, device_address=0x3C)
WIDTH = 128
HEIGHT = 32
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=WIDTH, height=HEIGHT)
# Make the display context
root = displayio.Group()
display.root_group = root
# clear the screen to black
color_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0x000000 # black
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
root.append(bg_sprite)
# Create the labels
LINE_HEIGHT = 10
x = 0
y = 5
self.text_area_1 = label.Label(terminalio.FONT, color=0xFFFFFF, x=x, y=y)
root.append(self.text_area_1)
y += LINE_HEIGHT
self.text_area_2 = label.Label(terminalio.FONT, color=0xFFFFFF, x=x, y=y)
root.append(self.text_area_2)
y += LINE_HEIGHT
self.text_area_3 = label.Label(terminalio.FONT, color=0xFFFFFF, x=x, y=y)
root.append(self.text_area_3)
# y += LINE_HEIGHT
# self.text_area_4 = label.Label(terminalio.FONT, color=0xFFFFFF, x=x, y=y)
# root.append(self.text_area_4)
def set_text_1(self, text):
self.text_area_1._set_text(text, 2.0)
def set_text_2(self, text):
self.text_area_2._set_text(text, 1.0)
def set_text_3(self, text):
self.text_area_3._set_text(text, 1.0)
# def set_text_4(self, text):
# self.text_area_4._set_text(text, 1.0)
def test(self):
self.set_text_1("This is a test.")
self.set_text_2("This is only a test.")
self.set_text_3("1234567890123456789012345")
time.sleep(1)
self.set_text_1("This was a test.")
time.sleep(1)
self.set_text_1("This will be a test.")
print("test done")
# while True:
# pass
# disp = oled_display()
# disp.test()
# while True:
# pass