adding cp and python demo code
This commit is contained in:
parent
c1c2897f2b
commit
108f763d40
4 changed files with 131 additions and 0 deletions
BIN
GC9A01A_Demo_Code/CircuitPython_GC9A01A/blinka_round.bmp
Normal file
BIN
GC9A01A_Demo_Code/CircuitPython_GC9A01A/blinka_round.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
61
GC9A01A_Demo_Code/CircuitPython_GC9A01A/code.py
Normal file
61
GC9A01A_Demo_Code/CircuitPython_GC9A01A/code.py
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import board
|
||||
import time
|
||||
import displayio
|
||||
import terminalio
|
||||
from adafruit_display_text.bitmap_label import Label
|
||||
import adafruit_imageload
|
||||
from fourwire import FourWire
|
||||
from vectorio import Circle
|
||||
from adafruit_gc9a01a import GC9A01A
|
||||
|
||||
spi = board.SPI()
|
||||
tft_cs = board.D5
|
||||
tft_dc = board.D6
|
||||
tft_reset = board.D9
|
||||
|
||||
displayio.release_displays()
|
||||
|
||||
display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=tft_reset)
|
||||
display = GC9A01A(display_bus, width=240, height=240)
|
||||
|
||||
# --- Default Shapes/Text Demo ---
|
||||
main_group = displayio.Group()
|
||||
display.root_group = main_group
|
||||
|
||||
bg_bitmap = displayio.Bitmap(240, 240, 2)
|
||||
color_palette = displayio.Palette(2)
|
||||
color_palette[0] = 0x00FF00 # Bright Green
|
||||
color_palette[1] = 0xAA0088 # Purple
|
||||
|
||||
bg_sprite = displayio.TileGrid(bg_bitmap, pixel_shader=color_palette, x=0, y=0)
|
||||
main_group.append(bg_sprite)
|
||||
|
||||
inner_circle = Circle(pixel_shader=color_palette, x=120, y=120, radius=100, color_index=1)
|
||||
main_group.append(inner_circle)
|
||||
|
||||
text_group = displayio.Group(scale=2, x=50, y=120)
|
||||
text = "Hello World!"
|
||||
text_area = Label(terminalio.FONT, text=text, color=0xFFFF00)
|
||||
text_group.append(text_area) # Subgroup for text scaling
|
||||
main_group.append(text_group)
|
||||
|
||||
# --- ImageLoad Demo ---
|
||||
blinka_group = displayio.Group()
|
||||
bitmap, palette = adafruit_imageload.load("/blinka_round.bmp",
|
||||
bitmap=displayio.Bitmap,
|
||||
palette=displayio.Palette)
|
||||
|
||||
grid = displayio.TileGrid(bitmap, pixel_shader=palette)
|
||||
blinka_group.append(grid)
|
||||
|
||||
while True:
|
||||
# show shapes/text
|
||||
display.root_group = main_group
|
||||
time.sleep(2)
|
||||
# show blinka bitmap
|
||||
display.root_group = blinka_group
|
||||
time.sleep(2)
|
||||
BIN
GC9A01A_Demo_Code/Python_GC9A01A/blinka_round.jpg
Normal file
BIN
GC9A01A_Demo_Code/Python_GC9A01A/blinka_round.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
70
GC9A01A_Demo_Code/Python_GC9A01A/code.py
Normal file
70
GC9A01A_Demo_Code/Python_GC9A01A/code.py
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
|
||||
# SPDX-FileCopyrightText: Adapted from Melissa LeBlanc-Williams's Pi Demo Code
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
'''Raspberry Pi Graphics example for the 240x240 Round TFT'''
|
||||
|
||||
import time
|
||||
import digitalio
|
||||
import board
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from adafruit_rgb_display import gc9a01a
|
||||
|
||||
BORDER = 20
|
||||
FONTSIZE = 24
|
||||
|
||||
cs_pin = digitalio.DigitalInOut(board.CE0)
|
||||
dc_pin = digitalio.DigitalInOut(board.D25)
|
||||
reset_pin = digitalio.DigitalInOut(board.D27)
|
||||
|
||||
BAUDRATE = 24000000
|
||||
|
||||
spi = board.SPI()
|
||||
|
||||
disp = gc9a01a.GC9A01A(spi, rotation=180,
|
||||
width=135, height=240,
|
||||
x_offset=53, y_offset=40,
|
||||
cs=cs_pin,
|
||||
dc=dc_pin,
|
||||
rst=reset_pin,
|
||||
baudrate=BAUDRATE,
|
||||
)
|
||||
|
||||
width = disp.width
|
||||
height = disp.height
|
||||
|
||||
# -------TEXT AND SHAPES---------
|
||||
image1 = Image.new("RGB", (width, height))
|
||||
draw1 = ImageDraw.Draw(image1)
|
||||
draw1.rectangle((0, 0, width, height), fill=(0, 255, 0)) # Green background
|
||||
|
||||
draw1.rectangle(
|
||||
(BORDER, BORDER, width - BORDER - 1, height - BORDER - 1), fill=(170, 0, 136)
|
||||
)
|
||||
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", FONTSIZE)
|
||||
text = "Hello\nWorld!"
|
||||
(font_width, font_height) = font.getsize(text)
|
||||
draw1.text(
|
||||
(30, height // 2 - font_height // 2-12),
|
||||
text,
|
||||
font=font,
|
||||
fill=(255, 255, 0),
|
||||
)
|
||||
|
||||
# ------BLINKA JPEG DISPLAY----------
|
||||
image2 = Image.open("blinka_round.jpg")
|
||||
image_ratio = image2.width / image2.height
|
||||
screen_ratio = width / height
|
||||
scaled_width = width
|
||||
scaled_height = image2.height * width // image2.width
|
||||
image2 = image2.resize((scaled_width, scaled_height), Image.BICUBIC)
|
||||
x = scaled_width // 2 - width // 2
|
||||
y = scaled_height // 2 - height // 2
|
||||
image2 = image2.crop((x, y, x + width, y + height))
|
||||
|
||||
while True:
|
||||
disp.image(image1) # show text
|
||||
time.sleep(2)
|
||||
disp.image(image2) # show blinka
|
||||
time.sleep(2)
|
||||
Loading…
Reference in a new issue