Last active
January 7, 2024 01:23
-
-
Save devjourney/e3b15b59ebaac3ea4a7d4cf25b91d662 to your computer and use it in GitHub Desktop.
CircuitPython ILI9341 TFT Showing Second Counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import board | |
import time | |
import terminalio | |
import displayio | |
import digitalio | |
from adafruit_display_text import label | |
import adafruit_ili9341 | |
# Release any resources currently in use for the displays | |
displayio.release_displays() | |
spi = board.SPI() | |
tft_cs = board.A0 | |
tft_dc = board.A1 | |
tft_reset = board.A2 | |
backlight_pin = board.A3 | |
led = digitalio.DigitalInOut(backlight_pin) | |
led.direction = digitalio.Direction.OUTPUT | |
display_bus = displayio.FourWire( | |
spi, command=tft_dc, chip_select=tft_cs, reset=tft_reset | |
) | |
display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240) | |
# Make the display context | |
splash = displayio.Group() | |
display.show(splash) | |
# Draw a green background | |
color_bitmap = displayio.Bitmap(320, 240, 1) | |
color_palette = displayio.Palette(1) | |
color_palette[0] = 0x00FF00 # Green | |
bg_sprite = displayio.TileGrid( | |
color_bitmap, pixel_shader=color_palette, x=0, y=0) | |
splash.append(bg_sprite) | |
# Draw a smaller inner rectangle in purple | |
inner_bitmap = displayio.Bitmap(280, 200, 1) | |
inner_palette = displayio.Palette(1) | |
inner_palette[0] = 0xAA0055 # Purple | |
inner_sprite = displayio.TileGrid( | |
inner_bitmap, pixel_shader=inner_palette, x=20, y=20) | |
splash.append(inner_sprite) | |
# Draw a label with to show the counter | |
counter = 0 | |
text_area = label.Label(terminalio.FONT, text="{:09d}".format(counter), color=0xFFFFFF) | |
text_group = displayio.Group(scale=3, x=80, y=120) | |
text_group.append(text_area) | |
splash.append(text_group) | |
# Turn on the LED and count forever | |
led.value = True | |
while True: | |
text_area.text = "{:09d}".format(counter) | |
time.sleep(1.0) | |
counter += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment