import os
import framebuf
from machine import Pin, SPI
import epaper
# Initialize the displays
spi = SPI(1, baudrate=2000000, polarity=0, phase=0)
cs1 = Pin(15, Pin.OUT)
dc1 = Pin(16, Pin.OUT)
rst1 = Pin(17, Pin.OUT)
busy1 = Pin(18, Pin.IN)
display1 = epaper.EPD(spi, cs1, dc1, rst1, busy1)
cs2 = Pin(19, Pin.OUT)
dc2 = Pin(20, Pin.OUT)
rst2 = Pin(21, Pin.OUT)
busy2 = Pin(22, Pin.IN)
display2 = epaper.EPD(spi, cs2, dc2, rst2, busy2)
def display_text(file_path, scroll_position):
display1.init()
display2.init()
display1.clear_frame()
display2.clear_frame()
display1.set_frame_memory(framebuf.FrameBuffer(bytearray(display1.width * display1.height // 8), display1.width, display1.height, framebuf.MONO_HLSB), 0, 0)
display2.set_frame_memory(framebuf.FrameBuffer(bytearray(display2.width * display2.height // 8), display2.width, display2.height, framebuf.MONO_HLSB), 0, 0)
line = 0
char_count = 0
with open(file_path, 'r') as file:
file.seek(scroll_position)
while True:
c = file.read(1)
if not c:
break
if line < 10:
display1.write(c)
elif line < 20:
display2.write(c)
char_count += 1
if c == '\n':
line += 1
if line == 10:
display1.display_frame()
elif line == 20:
display2.display_frame()
break
scroll_position += char_count
display1.display_frame()
display2.display_frame()
# Example usage
display_text('/path/to/textfile.txt', 0)