aa0e193604388cdd3ec8ac2de8b286b2bef639fc
4 from PIL
import Image
, ImageDraw
, ImageFont
6 print("""lcd.py - Hello, World! example on the 0.96" LCD.
12 # Create LCD class instance.
25 # Width and height to calculate text position.
29 # New canvas to draw on.
30 img
= Image
.new('RGB', (WIDTH
, HEIGHT
), color
=(0, 0, 0))
31 draw
= ImageDraw
.Draw(img
)
35 font
= ImageFont
.truetype("fonts/Asap/Asap-Bold.ttf", font_size
)
36 text_colour
= (255, 255, 255)
37 back_colour
= (0, 170, 170)
39 message
= "Hello, World!"
40 size_x
, size_y
= draw
.textsize(message
, font
)
42 # Calculate text position
43 x
= (WIDTH
- size_x
) / 2
44 y
= (HEIGHT
/ 2) - (size_y
/ 2)
46 # Draw background rectangle and write text.
47 draw
.rectangle((0, 0, 160, 80), back_colour
)
48 draw
.text((x
, y
), message
, font
=font
, fill
=text_colour
)
56 # Turn off backlight on control-c
57 except KeyboardInterrupt: