Skip to content

Commit 7d08a07

Browse files
committed
bonnet demo
1 parent 8022b34 commit 7d08a07

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

examples/epd_bonnet.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import digitalio
2+
import busio
3+
import board
4+
5+
from PIL import Image
6+
from PIL import ImageDraw
7+
from PIL import ImageFont
8+
from adafruit_epd.epd import Adafruit_EPD
9+
from adafruit_epd.ssd1675b import Adafruit_SSD1675B # pylint: disable=unused-import
10+
11+
# create the spi device and pins we will need
12+
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
13+
ecs = digitalio.DigitalInOut(board.D8)
14+
dc = digitalio.DigitalInOut(board.D22)
15+
rst = digitalio.DigitalInOut(board.D27)
16+
busy = digitalio.DigitalInOut(board.D17)
17+
18+
# give them all to our driver
19+
display = Adafruit_SSD1675B(122, 250, spi, # 2.13" HD mono display (rev B)
20+
cs_pin=ecs, dc_pin=dc, sramcs_pin=None,
21+
rst_pin=rst, busy_pin=busy)
22+
display.rotation = 1
23+
24+
# Create blank image for drawing.
25+
# Make sure to create image with mode '1' for 1-bit color.
26+
width = display.width
27+
height = display.height
28+
image = Image.new('RGB', (width, height))
29+
30+
WHITE = (0xFF, 0xFF, 0xFF)
31+
BLACK = (0x00, 0x00, 0x00)
32+
33+
# clear the buffer
34+
display.fill(Adafruit_EPD.WHITE)
35+
36+
# Get drawing object to draw on image.
37+
draw = ImageDraw.Draw(image)
38+
# empty it
39+
draw.rectangle((0, 0, width, height), fill=WHITE)
40+
41+
# Draw an outline box
42+
draw.rectangle((1, 1, width-2, height-2), outline=BLACK, fill=WHITE)
43+
# Draw some shapes.
44+
# First define some constants to allow easy resizing of shapes.
45+
padding = 5
46+
shape_width = 30
47+
top = padding
48+
bottom = height-padding
49+
# Move left to right keeping track of the current x position for drawing shapes.
50+
x = padding
51+
# Draw an ellipse.
52+
draw.ellipse((x, top , x+shape_width, bottom), outline=BLACK, fill=WHITE)
53+
x += shape_width+padding
54+
# Draw a rectangle.
55+
draw.rectangle((x, top, x+shape_width, bottom), outline=WHITE, fill=BLACK)
56+
x += shape_width+padding
57+
# Draw a triangle.
58+
draw.polygon([(x, bottom), (x+shape_width/2, top), (x+shape_width, bottom)],
59+
outline=BLACK, fill=WHITE)
60+
x += shape_width+padding
61+
# Draw an X.
62+
draw.line((x, bottom, x+shape_width, top), fill=BLACK)
63+
draw.line((x, top, x+shape_width, bottom), fill=BLACK)
64+
x += shape_width+padding
65+
66+
# Load default font.
67+
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 20)
68+
69+
# Alternatively load a TTF font. Make sure the .ttf font
70+
# file is in the same directory as the python script!
71+
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
72+
#font = ImageFont.truetype('Minecraftia.ttf', 8)
73+
74+
# Write two lines of text.
75+
draw.text((x, top), 'Hello', font=font, fill=BLACK)
76+
draw.text((x, top+20), 'World!', font=font, fill=BLACK)
77+
# Display image.
78+
display.image(image)
79+
80+
display.display()

0 commit comments

Comments
 (0)