mirror of
https://github.com/pimoroni/st7735-python.git
synced 2025-01-05 22:40:25 +03:00
45 lines
978 B
Python
45 lines
978 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=9,
|
|
backlight=19, # 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)
|