|
| 1 | +# SPDX-FileCopyrightText: 2019 Melissa LeBlanc-Williams for Adafruit Industries |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +""" |
| 5 | +ePaper Display Shapes and Text demo using the Pillow Library. |
| 6 | +3.52" Quad Color 384x180 display |
| 7 | +https://www.adafruit.com/product/6414 |
| 8 | +""" |
| 9 | + |
| 10 | +import board |
| 11 | +import busio |
| 12 | +import digitalio |
| 13 | +from PIL import Image, ImageDraw, ImageFont |
| 14 | + |
| 15 | +from adafruit_epd.jd79667 import Adafruit_JD79667 |
| 16 | + |
| 17 | +# RGB colors |
| 18 | +WHITE = (255, 255, 255) |
| 19 | +BLACK = (0, 0, 0) |
| 20 | +RED = (255, 0, 0) |
| 21 | +YELLOW = (255, 255, 0) |
| 22 | + |
| 23 | +# Create the SPI device and pins |
| 24 | +spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) |
| 25 | +ecs = digitalio.DigitalInOut(board.CE0) |
| 26 | +dc = digitalio.DigitalInOut(board.D22) |
| 27 | +srcs = None # No SRAM |
| 28 | +rst = digitalio.DigitalInOut(board.D27) |
| 29 | +busy = digitalio.DigitalInOut(board.D17) |
| 30 | + |
| 31 | +display = Adafruit_JD79667( |
| 32 | + 180, |
| 33 | + 384, |
| 34 | + spi, |
| 35 | + cs_pin=ecs, |
| 36 | + dc_pin=dc, |
| 37 | + sramcs_pin=srcs, |
| 38 | + rst_pin=rst, |
| 39 | + busy_pin=busy, |
| 40 | +) |
| 41 | + |
| 42 | +display.rotation = 3 |
| 43 | + |
| 44 | +# Get display dimensions |
| 45 | +width = display.width |
| 46 | +height = display.height |
| 47 | +image = Image.new("RGB", (width, height)) |
| 48 | +# Get drawing object |
| 49 | +draw = ImageDraw.Draw(image) |
| 50 | + |
| 51 | +# Fill background with white |
| 52 | +draw.rectangle((0, 0, width, height), fill=WHITE) |
| 53 | + |
| 54 | +# Draw a border |
| 55 | +draw.rectangle((0, 0, width - 1, height - 1), outline=BLACK, fill=WHITE) |
| 56 | + |
| 57 | +# Draw some shapes to demonstrate all four colors |
| 58 | +padding = 10 |
| 59 | +shape_width = 30 |
| 60 | +top = padding + 10 |
| 61 | +bottom = height - padding - 10 |
| 62 | + |
| 63 | +# Starting x position |
| 64 | +x = padding + 10 |
| 65 | + |
| 66 | +# Draw an ellipse filled with red |
| 67 | +draw.ellipse((x, top, x + shape_width, bottom), outline=RED, fill=None) |
| 68 | +x += shape_width + padding |
| 69 | + |
| 70 | +# Draw a rectangle filled with yellow |
| 71 | +draw.rectangle((x, top, x + shape_width, bottom), outline=YELLOW, fill=BLACK) |
| 72 | +x += shape_width + padding |
| 73 | + |
| 74 | +# Draw a triangle filled with red |
| 75 | +draw.polygon( |
| 76 | + [(x, bottom), (x + shape_width / 2, top), (x + shape_width, bottom)], |
| 77 | + outline=BLACK, |
| 78 | + fill=YELLOW, |
| 79 | +) |
| 80 | +x += shape_width + padding |
| 81 | + |
| 82 | +# Draw an X with red and yellow lines |
| 83 | +draw.line((x, bottom, x + shape_width, top), fill=RED) |
| 84 | +draw.line((x, top, x + shape_width, bottom), fill=BLACK) |
| 85 | +x += shape_width + padding |
| 86 | + |
| 87 | +# Add some text |
| 88 | +font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 28) |
| 89 | + |
| 90 | +# Draw text in different colors |
| 91 | +draw.text((x, top), "Hello", font=font, fill=BLACK) |
| 92 | +draw.text((x, top + 28), "World!", font=font, fill=RED) |
| 93 | +draw.text((x, top + (28*2)), "Quad", font=font, fill=YELLOW) |
| 94 | +draw.text((x, top + (28*3)), "Color!", font=font, fill=BLACK) |
| 95 | + |
| 96 | +display.image(image) |
| 97 | + |
| 98 | +display.display() |
0 commit comments