|
| 1 | +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +import digitalio |
| 5 | +import busio |
| 6 | +import board |
| 7 | +from adafruit_epd.epd import Adafruit_EPD |
| 8 | +import time |
| 9 | + |
| 10 | +from PIL import Image |
| 11 | +from PIL import ImageDraw |
| 12 | +from PIL import ImageFont |
| 13 | + |
| 14 | +# create the spi device and pins we will need |
| 15 | +spi = busio.SPI(board.EPD_SCK, MOSI=board.EPD_MOSI, MISO=None) |
| 16 | +epd_cs = digitalio.DigitalInOut(board.EPD_CS) |
| 17 | +epd_dc = digitalio.DigitalInOut(board.EPD_DC) |
| 18 | +epd_reset = digitalio.DigitalInOut(board.EPD_RESET) |
| 19 | +epd_busy = digitalio.DigitalInOut(board.EPD_BUSY) |
| 20 | +srcs = None |
| 21 | + |
| 22 | +from adafruit_epd.ssd1680 import Adafruit_SSD1680 |
| 23 | +display = Adafruit_SSD1680(122, 250, spi, cs_pin=epd_cs, dc_pin=epd_dc, |
| 24 | + sramcs_pin=srcs, rst_pin=epd_reset, |
| 25 | + busy_pin=epd_busy) |
| 26 | + |
| 27 | +display.rotation = 3 |
| 28 | +# Create blank image for drawing. |
| 29 | +# Make sure to create image with mode '1' for 1-bit color. |
| 30 | +width = display.width |
| 31 | +height = display.height |
| 32 | +image = Image.new("RGB", (width, height)) |
| 33 | + |
| 34 | +WHITE = (0xFF, 0xFF, 0xFF) |
| 35 | +BLACK = (0x00, 0x00, 0x00) |
| 36 | + |
| 37 | +# clear the display |
| 38 | +display.fill(Adafruit_EPD.WHITE) |
| 39 | + |
| 40 | +# Get drawing object to draw on image. |
| 41 | +draw = ImageDraw.Draw(image) |
| 42 | +# empty it |
| 43 | +draw.rectangle((0, 0, width, height), fill=WHITE) |
| 44 | + |
| 45 | +# Draw an outline box |
| 46 | +draw.rectangle((1, 1, width - 2, height - 2), outline=BLACK, fill=WHITE) |
| 47 | +# Draw some shapes. |
| 48 | +# First define some constants to allow easy resizing of shapes. |
| 49 | +padding = 5 |
| 50 | +shape_width = 30 |
| 51 | +top = padding |
| 52 | +bottom = height - padding |
| 53 | +# Move left to right keeping track of the current x position for drawing shapes. |
| 54 | +x = padding |
| 55 | +# Draw an ellipse. |
| 56 | +draw.ellipse((x, top, x + shape_width, bottom), outline=BLACK, fill=WHITE) |
| 57 | +x += shape_width + padding |
| 58 | +# Draw a rectangle. |
| 59 | +draw.rectangle((x, top, x + shape_width, bottom), outline=WHITE, fill=BLACK) |
| 60 | +x += shape_width + padding |
| 61 | +# Draw a triangle. |
| 62 | +draw.polygon( |
| 63 | + [(x, bottom), (x + shape_width / 2, top), (x + shape_width, bottom)], |
| 64 | + outline=BLACK, |
| 65 | + fill=WHITE, |
| 66 | +) |
| 67 | +x += shape_width + padding |
| 68 | +# Draw an X. |
| 69 | +draw.line((x, bottom, x + shape_width, top), fill=BLACK) |
| 70 | +draw.line((x, top, x + shape_width, bottom), fill=BLACK) |
| 71 | +x += shape_width + padding |
| 72 | + |
| 73 | +# Load default font. |
| 74 | +font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 20) |
| 75 | + |
| 76 | +# Alternatively load a TTF font. Make sure the .ttf font |
| 77 | +# file is in the same directory as the python script! |
| 78 | +# Some other nice fonts to try: http://www.dafont.com/bitmap.php |
| 79 | +# font = ImageFont.truetype('Minecraftia.ttf', 8) |
| 80 | + |
| 81 | +# Write two lines of text. |
| 82 | +draw.text((x, top), "Hello", font=font, fill=BLACK) |
| 83 | +draw.text((x, top + 20), "World!", font=font, fill=BLACK) |
| 84 | + |
| 85 | +display.image(image) |
| 86 | +display.display() |
| 87 | + |
| 88 | +time.sleep(10) |
| 89 | + |
| 90 | +blinkaimage = Image.open('examples/epd_bonnet_blinka_250x122.bmp') |
| 91 | +display.image(blinkaimage) |
| 92 | +display.display() |
| 93 | + |
0 commit comments