bonnet demo
This commit is contained in:
parent
8022b3427e
commit
7d08a07fa3
1 changed files with 80 additions and 0 deletions
80
examples/epd_bonnet.py
Normal file
80
examples/epd_bonnet.py
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
import digitalio
|
||||
import busio
|
||||
import board
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ImageDraw
|
||||
from PIL import ImageFont
|
||||
from adafruit_epd.epd import Adafruit_EPD
|
||||
from adafruit_epd.ssd1675b import Adafruit_SSD1675B # pylint: disable=unused-import
|
||||
|
||||
# create the spi device and pins we will need
|
||||
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
|
||||
ecs = digitalio.DigitalInOut(board.D8)
|
||||
dc = digitalio.DigitalInOut(board.D22)
|
||||
rst = digitalio.DigitalInOut(board.D27)
|
||||
busy = digitalio.DigitalInOut(board.D17)
|
||||
|
||||
# give them all to our driver
|
||||
display = Adafruit_SSD1675B(122, 250, spi, # 2.13" HD mono display (rev B)
|
||||
cs_pin=ecs, dc_pin=dc, sramcs_pin=None,
|
||||
rst_pin=rst, busy_pin=busy)
|
||||
display.rotation = 1
|
||||
|
||||
# Create blank image for drawing.
|
||||
# Make sure to create image with mode '1' for 1-bit color.
|
||||
width = display.width
|
||||
height = display.height
|
||||
image = Image.new('RGB', (width, height))
|
||||
|
||||
WHITE = (0xFF, 0xFF, 0xFF)
|
||||
BLACK = (0x00, 0x00, 0x00)
|
||||
|
||||
# clear the buffer
|
||||
display.fill(Adafruit_EPD.WHITE)
|
||||
|
||||
# Get drawing object to draw on image.
|
||||
draw = ImageDraw.Draw(image)
|
||||
# empty it
|
||||
draw.rectangle((0, 0, width, height), fill=WHITE)
|
||||
|
||||
# Draw an outline box
|
||||
draw.rectangle((1, 1, width-2, height-2), outline=BLACK, fill=WHITE)
|
||||
# Draw some shapes.
|
||||
# First define some constants to allow easy resizing of shapes.
|
||||
padding = 5
|
||||
shape_width = 30
|
||||
top = padding
|
||||
bottom = height-padding
|
||||
# Move left to right keeping track of the current x position for drawing shapes.
|
||||
x = padding
|
||||
# Draw an ellipse.
|
||||
draw.ellipse((x, top , x+shape_width, bottom), outline=BLACK, fill=WHITE)
|
||||
x += shape_width+padding
|
||||
# Draw a rectangle.
|
||||
draw.rectangle((x, top, x+shape_width, bottom), outline=WHITE, fill=BLACK)
|
||||
x += shape_width+padding
|
||||
# Draw a triangle.
|
||||
draw.polygon([(x, bottom), (x+shape_width/2, top), (x+shape_width, bottom)],
|
||||
outline=BLACK, fill=WHITE)
|
||||
x += shape_width+padding
|
||||
# Draw an X.
|
||||
draw.line((x, bottom, x+shape_width, top), fill=BLACK)
|
||||
draw.line((x, top, x+shape_width, bottom), fill=BLACK)
|
||||
x += shape_width+padding
|
||||
|
||||
# Load default font.
|
||||
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 20)
|
||||
|
||||
# Alternatively load a TTF font. Make sure the .ttf font
|
||||
# file is in the same directory as the python script!
|
||||
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
|
||||
#font = ImageFont.truetype('Minecraftia.ttf', 8)
|
||||
|
||||
# Write two lines of text.
|
||||
draw.text((x, top), 'Hello', font=font, fill=BLACK)
|
||||
draw.text((x, top+20), 'World!', font=font, fill=BLACK)
|
||||
# Display image.
|
||||
display.image(image)
|
||||
|
||||
display.display()
|
||||
Loading…
Reference in a new issue