-
Notifications
You must be signed in to change notification settings - Fork 1
/
i2c_oled_ssd1306_basics.py
88 lines (71 loc) · 2.37 KB
/
i2c_oled_ssd1306_basics.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
from micropython import const
from machine import Pin, SoftI2C
from lib.ssd1306 import SSD1306_I2C
from utime import sleep
DISPLAY_WIDTH = const(128)
DISPLAY_HEIGHT = const(64)
DISPLAY_SDA_PIN = const(21)
DISPLAY_SCL_PIN = const(22)
MICROPYTHON_ICON = [
[0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1],
[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1],
[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1],
[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1],
[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1],
[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1],
[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1],
[1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1],
[1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1]
]
def scroll_vertical_in_out(content: list) -> None:
"""
scrolls the content from top to down
:param content: list of different strings per row to display
:return: None
"""
global oled
for item in range(0, (DISPLAY_HEIGHT * 2 + 1), 1):
for line in content:
oled.text(line[2], line[0], -DISPLAY_HEIGHT + item + line[1])
oled.show()
if item != DISPLAY_HEIGHT:
oled.fill(0)
if __name__ == '__main__':
i2c = SoftI2C(sda=Pin(DISPLAY_SDA_PIN), scl=Pin(DISPLAY_SCL_PIN))
oled = SSD1306_I2C(DISPLAY_WIDTH, DISPLAY_HEIGHT, i2c)
oled.fill(0)
print('[INFO] Sequence 1')
oled.rect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, 1)
start_x = 12
start_y = 12
for y, row in enumerate(MICROPYTHON_ICON):
for x, c in enumerate(row):
oled.pixel(x + start_x, y + start_y, c)
oled.text('MicroPython', 30, 15)
oled.show()
sleep(1)
print('[INFO] Sequence 2')
oled.text('on ESP32', 35, 35)
oled.show()
sleep(1)
print('[INFO] Sequence 3')
for i in range(10):
oled.invert(1)
sleep(0.1)
oled.invert(0)
sleep(0.1)
print('[INFO] Sequence 4')
for index in range(DISPLAY_WIDTH, -1, -1):
oled.fill_rect(index, 0, 1, DISPLAY_HEIGHT, 0)
oled.show()
sleep(0.005)
oled.fill(0)
print('[INFO] Sequence 5')
text_1 = "Damien P. George"
text_2 = "many thanks to"
text_3 = "All honor and"
screen = [[0, 0, text_1], [0, 16, text_2], [0, 32, text_3]]
scroll_vertical_in_out(screen)