Files
st7735-python-pimoroni/examples/scrolling-text.py
2023-11-08 09:19:00 +00:00

45 lines
984 B
Python

import time
from PIL import Image, ImageDraw, ImageFont
import st7735
MESSAGE = "Hello World! How are you today?"
# Create ST7735 LCD display class.
disp = st7735.ST7735(
port=0,
cs=st7735.BG_SPI_CS_FRONT, # BG_SPI_CSB_BACK or BG_SPI_CS_FRONT
dc="GPIO9",
backlight="GPIO19", # 18 for back BG slot, 19 for front BG slot.
rotation=90,
spi_speed_hz=10000000
)
# 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 = 160
text_y = (80 - size_y) // 2
t_start = time.time()
while True:
x = (time.time() - t_start) * 100
x %= (size_x + 160)
draw.rectangle((0, 0, 160, 80), (0, 0, 0))
draw.text((int(text_x - x), text_y), MESSAGE, font=font, fill=(255, 255, 255))
disp.display(img)