4 from PIL
import Image
, ImageDraw
, ImageFont
5 from fonts
.ttf
import RobotoMedium
as UserFont
9 format
='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
11 datefmt
='%Y-%m-%d %H:%M:%S')
13 logging
.info("""lcd.py - Hello, World! example on the 0.96" LCD.
19 # Create LCD class instance.
32 # Width and height to calculate text position.
36 # New canvas to draw on.
37 img
= Image
.new('RGB', (WIDTH
, HEIGHT
), color
=(0, 0, 0))
38 draw
= ImageDraw
.Draw(img
)
42 font
= ImageFont
.truetype(UserFont
, font_size
)
43 text_colour
= (255, 255, 255)
44 back_colour
= (0, 170, 170)
46 message
= "Hello, World!"
47 size_x
, size_y
= draw
.textsize(message
, font
)
49 # Calculate text position
50 x
= (WIDTH
- size_x
) / 2
51 y
= (HEIGHT
/ 2) - (size_y
/ 2)
53 # Draw background rectangle and write text.
54 draw
.rectangle((0, 0, 160, 80), back_colour
)
55 draw
.text((x
, y
), message
, font
=font
, fill
=text_colour
)
63 # Turn off backlight on control-c
64 except KeyboardInterrupt: