Last active
May 8, 2023 17:30
-
-
Save arthurescriou/0df401bb0cc46aa8764e01433c2e938e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 digitalio | |
| import adafruit_rgb_display.ili9341 as ili9341 | |
| from PIL import Image, ImageDraw, ImageFont | |
| # Initialize the display | |
| spi = board.SPI() | |
| tft_cs = digitalio.DigitalInOut(board.CE0) | |
| tft_dc = digitalio.DigitalInOut(board.D24) | |
| display = ili9341.ILI9341(spi, cs=tft_cs, dc=tft_dc) | |
| # Create an image | |
| image = Image.new("RGB", (display.width, display.height)) | |
| draw = ImageDraw.Draw(image) | |
| draw.rectangle((0, 0, display.width, display.height), fill=(255, 255, 255)) | |
| # Draw some text | |
| font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 20) | |
| text = "Hello World!" | |
| text_width, text_height = draw.textsize(text, font) | |
| x = (display.width - text_width) // 2 | |
| y = (display.height - text_height) // 2 | |
| draw.text((x, y), text, font=font, fill=(0, 0, 0)) | |
| # Display the image | |
| display.image(image) | |
| display.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment