from PIL import Image from PIL import ImageDraw from PIL import ImageFont import time import ST7789 MESSAGE = "Hello World! How are you today?" # Create ST7789 LCD display class. disp = ST7789.ST7789( port=0, cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CSB_BACK or BG_SPI_CS_FRONT dc=9, backlight=19, # 18 for back BG slot, 19 for front BG slot. spi_speed_hz=80 * 1000 * 1000 ) # Initialize display. disp.begin() WIDTH = disp.width HEIGHT = disp.height img = Image.new('RGB', (WIDTH, HEIGHT), color=(0, 0, 0)) draw = ImageDraw.Draw(img) font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 30) size_x, size_y = draw.textsize(MESSAGE, font) text_x = disp.width text_y = (80 - size_y) // 2 t_start = time.time() while True: x = (time.time() - t_start) * 100 x %= (size_x + disp.width) draw.rectangle((0, 0, disp.width, 80), (0, 0, 0)) draw.text((int(text_x - x), text_y), MESSAGE, font=font, fill=(255, 255, 255)) disp.display(img)