Skip to content

Commit fbf893b

Browse files
committed
adding cpython example
1 parent a26563c commit fbf893b

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Loading
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
2+
# SPDX-FileCopyrightText: Adapted from Melissa LeBlanc-Williams's Pi Demo Code
3+
#
4+
# SPDX-License-Identifier: MIT
5+
6+
'''Raspberry Pi Graphics example for the Vertical Newxie TFT'''
7+
8+
import time
9+
import digitalio
10+
import board
11+
from PIL import Image, ImageDraw, ImageFont
12+
from adafruit_rgb_display import st7789
13+
14+
BORDER = 20
15+
FONTSIZE = 24
16+
17+
cs_pin = digitalio.DigitalInOut(board.CE0)
18+
dc_pin = digitalio.DigitalInOut(board.D25)
19+
reset_pin = digitalio.DigitalInOut(board.D24)
20+
21+
BAUDRATE = 24000000
22+
23+
spi = board.SPI()
24+
25+
disp = st7789.ST7789(spi, rotation=180,
26+
width=135, height=240,
27+
x_offset=53, y_offset=40,
28+
cs=cs_pin,
29+
dc=dc_pin,
30+
rst=reset_pin,
31+
baudrate=BAUDRATE,
32+
)
33+
34+
width = disp.width
35+
height = disp.height
36+
37+
# -------TEXT AND SHAPES---------
38+
image1 = Image.new("RGB", (width, height))
39+
draw1 = ImageDraw.Draw(image1)
40+
draw1.rectangle((0, 0, width, height), fill=(0, 255, 0)) # Green background
41+
42+
draw1.rectangle(
43+
(BORDER, BORDER, width - BORDER - 1, height - BORDER - 1), fill=(170, 0, 136)
44+
)
45+
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", FONTSIZE)
46+
text = "Hello\nWorld!"
47+
(font_width, font_height) = font.getsize(text)
48+
draw1.text(
49+
(30, height // 2 - font_height // 2-12),
50+
text,
51+
font=font,
52+
fill=(255, 255, 0),
53+
)
54+
55+
# ------ADABOT JPEG DISPLAY----------
56+
image2 = Image.open("adabot.jpg")
57+
image_ratio = image2.width / image2.height
58+
screen_ratio = width / height
59+
scaled_width = width
60+
scaled_height = image2.height * width // image2.width
61+
image2 = image2.resize((scaled_width, scaled_height), Image.BICUBIC)
62+
x = scaled_width // 2 - width // 2
63+
y = scaled_height // 2 - height // 2
64+
image2 = image2.crop((x, y, x + width, y + height))
65+
66+
while True:
67+
disp.image(image1) # show text
68+
time.sleep(2)
69+
disp.image(image2) # show adabot
70+
time.sleep(2)

0 commit comments

Comments
 (0)