72 lines
1.5 KiB
Python
72 lines
1.5 KiB
Python
from machine import Pin, SoftI2C
|
|
import framebuf
|
|
import json
|
|
import machine
|
|
import network
|
|
import ubinascii
|
|
import utime
|
|
|
|
import ssd1306
|
|
|
|
|
|
last_update = 0
|
|
|
|
i2c = SoftI2C(sda=Pin(14), scl=Pin(15))
|
|
oled_width = const(128)
|
|
oled_height = const(32)
|
|
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
|
|
buf = bytearray((oled_height // 8) * oled_width)
|
|
fbuf = framebuf.FrameBuffer(buf, oled_width, oled_height, framebuf.MONO_VLSB)
|
|
|
|
|
|
SCRIPT = """
|
|
Hello!
|
|
|
|
This is a sample
|
|
script!
|
|
This is even more
|
|
text to show!
|
|
"""
|
|
|
|
|
|
def flipx(buf: bytearray, width: int, height: int) -> None:
|
|
view = memoryview(buf)
|
|
for y in range(height):
|
|
start = y * width
|
|
view[start : start + width] = bytearray(reversed(view[start : start + width]))
|
|
|
|
|
|
def linebuffers(text):
|
|
buf = bytearray(oled_width)
|
|
fbuf = framebuf.FrameBuffer(
|
|
buf,
|
|
oled_width,
|
|
8,
|
|
framebuf.MONO_VLSB,
|
|
)
|
|
for line in text:
|
|
fbuf.fill(0)
|
|
fbuf.text(line, 0, 0)
|
|
flipx(buf, oled_width, 1)
|
|
yield fbuf
|
|
|
|
|
|
def loop():
|
|
lines = SCRIPT.strip().splitlines()
|
|
# Pad out the ending with blank lines
|
|
lines += [""] * (oled_height // 8)
|
|
# Start out with a blank screen
|
|
oled.framebuf.fill(0)
|
|
oled.show()
|
|
for line in linebuffers(lines):
|
|
for i in range(8):
|
|
utime.sleep(0.1)
|
|
oled.framebuf.scroll(0, -1)
|
|
oled.framebuf.blit(line, 0, oled_height - i)
|
|
oled.show()
|
|
oled.framebuf.fill(0)
|
|
oled.show()
|
|
|
|
|
|
loop()
|