-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from makermelissa/master
Added EPD Pillow Shapes and Text demo
- Loading branch information
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
""" | ||
ePaper Display Shapes and Text demo using the Pillow Library. | ||
Written by Melissa LeBlanc-Williams for Adafruit Industries | ||
""" | ||
|
||
import digitalio | ||
import busio | ||
import board | ||
from PIL import Image, ImageDraw, ImageFont | ||
from adafruit_epd.il0373 import Adafruit_IL0373 | ||
from adafruit_epd.il91874 import Adafruit_IL91874 # pylint: disable=unused-import | ||
from adafruit_epd.il0398 import Adafruit_IL0398 # pylint: disable=unused-import | ||
from adafruit_epd.ssd1608 import Adafruit_SSD1608 # pylint: disable=unused-import | ||
from adafruit_epd.ssd1675 import Adafruit_SSD1675 # pylint: disable=unused-import | ||
|
||
# First define some color constants | ||
WHITE = (0xFF, 0xFF, 0xFF) | ||
BLACK = (0x00, 0x00, 0x00) | ||
RED = (0xFF, 0x00, 0x00) | ||
|
||
# Next define some constants to allow easy resizing of shapes and colors | ||
BORDER = 20 | ||
FONTSIZE = 24 | ||
BACKGROUND_COLOR = BLACK | ||
FOREGROUND_COLOR = WHITE | ||
TEXT_COLOR = RED | ||
|
||
# create the spi device and pins we will need | ||
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) | ||
ecs = digitalio.DigitalInOut(board.CE0) | ||
dc = digitalio.DigitalInOut(board.D22) | ||
srcs = None | ||
rst = digitalio.DigitalInOut(board.D27) | ||
busy = digitalio.DigitalInOut(board.D17) | ||
|
||
# give them all to our driver | ||
#display = Adafruit_SSD1608(200, 200, spi, # 1.54" HD mono display | ||
#display = Adafruit_SSD1675(122, 250, spi, # 2.13" HD mono display | ||
#display = Adafruit_IL91874(176, 264, spi, # 2.7" Tri-color display | ||
#display = Adafruit_IL0373(152, 152, spi, # 1.54" Tri-color display | ||
#display = Adafruit_IL0373(128, 296, spi, # 2.9" Tri-color display | ||
#display = Adafruit_IL0398(400, 300, spi, # 4.2" Tri-color display | ||
display = Adafruit_IL0373(104, 212, spi, # 2.13" Tri-color display | ||
cs_pin=ecs, dc_pin=dc, sramcs_pin=srcs, | ||
rst_pin=rst, busy_pin=busy) | ||
|
||
# IF YOU HAVE A FLEXIBLE DISPLAY (2.13" or 2.9") uncomment these lines! | ||
#display.set_black_buffer(1, False) | ||
#display.set_color_buffer(1, False) | ||
|
||
display.rotation = 1 | ||
|
||
image = Image.new('RGB', (display.width, display.height)) | ||
|
||
# Get drawing object to draw on image. | ||
draw = ImageDraw.Draw(image) | ||
|
||
# Draw a filled box as the background | ||
draw.rectangle((0, 0, display.width, display.height), fill=BACKGROUND_COLOR) | ||
|
||
# Draw a smaller inner foreground rectangle | ||
draw.rectangle((BORDER, BORDER, display.width - BORDER - 1, display.height - BORDER - 1), | ||
fill=FOREGROUND_COLOR) | ||
|
||
# Load a TTF Font | ||
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', FONTSIZE) | ||
|
||
# Draw Some Text | ||
text = "Hello World!" | ||
(font_width, font_height) = font.getsize(text) | ||
draw.text((display.width//2 - font_width//2, display.height//2 - font_height//2), | ||
text, font=font, fill=TEXT_COLOR) | ||
|
||
# Display image. | ||
display.image(image) | ||
display.display() |