Last active
August 15, 2020 19:28
-
-
Save vsefer/20649c764f089654ee6cd8e024f93acb to your computer and use it in GitHub Desktop.
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 time | |
import sys | |
import os | |
import digitalio | |
import board | |
from PIL import Image, ImageDraw, ImageFont | |
from datetime import datetime | |
import adafruit_rgb_display.ili9341 as ili9341 | |
import adafruit_rgb_display.st7789 as st7789 # pylint: disable=unused-import | |
import adafruit_rgb_display.hx8357 as hx8357 # pylint: disable=unused-import | |
import adafruit_rgb_display.st7735 as st7735 # pylint: disable=unused-import | |
import adafruit_rgb_display.ssd1351 as ssd1351 # pylint: disable=unused-import | |
import adafruit_rgb_display.ssd1331 as ssd1331 # pylint: disable=unused-import | |
# Configuration for CS and DC pins (these are PiTFT defaults): | |
cs_pin = digitalio.DigitalInOut(board.CE0) | |
dc_pin = digitalio.DigitalInOut(board.D25) | |
reset_pin = digitalio.DigitalInOut(board.D24) | |
# Config for display baudrate (default max is 24mhz): | |
BAUDRATE = 24000000 | |
# Setup SPI bus using hardware SPI: | |
spi = board.SPI() | |
disp = ili9341.ILI9341( | |
spi, | |
rotation=90, # 2.2", 2.4", 2.8", 3.2" ILI9341 | |
cs=cs_pin, | |
dc=dc_pin, | |
rst=reset_pin, | |
baudrate=BAUDRATE, | |
) | |
# pylint: enable=line-too-long | |
def main(): | |
# Create blank image for drawing. | |
# Make sure to create image with mode 'RGB' for full color. | |
if disp.rotation % 180 == 90: | |
height = disp.width # we swap height/width to rotate it to landscape! | |
width = disp.height | |
else: | |
width = disp.width # we swap height/width to rotate it to landscape! | |
height = disp.height | |
image = Image.new("RGB", (width, height)) | |
text = Image.new("RGB", (width, height)) | |
# Get drawing object to draw on image. | |
draw = ImageDraw.Draw(image) | |
write = ImageDraw.Draw(text) | |
# Draw a black filled box to clear the image. | |
# draw.rectangle((0, 0, width, height), outline=0, fill=(0, 0, 0)) | |
# disp.image(image) | |
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 64) | |
while True: | |
# Draw a black filled box to clear the image. | |
draw.rectangle((0, 0, width, height), outline=0, fill=0) | |
# Draw text. | |
image = Image.open("/home/pi/pidi/test.jpg") | |
image = image.resize((200, 200), Image.BICUBIC) | |
# image = image.crop((10, 50, 150, 200)) | |
write.text((0,0), "Jebem ti mater", font=font, fill="YELLOW") | |
# Draw the image buffer. | |
disp.image(text) | |
disp.image(image) | |
# Pause briefly before drawing next frame. | |
time.sleep(1) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment