Transitional fix for new LTR559 library
[EVA-2020-02-2.git] / examples / lcd.py
CommitLineData
a155e335
SM
1#!/usr/bin/env python
2
3import ST7735
4from PIL import Image, ImageDraw, ImageFont
10b73e18 5import logging
a155e335 6
10b73e18
CM
7logging.basicConfig(
8 format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
9 level=logging.INFO,
10 datefmt='%Y-%m-%d %H:%M:%S')
11
12logging.info("""lcd.py - Hello, World! example on the 0.96" LCD.
a155e335
SM
13
14Press Ctrl+C to exit!
15
16""")
17
18# Create LCD class instance.
19disp = ST7735.ST7735(
20 port=0,
21 cs=1,
22 dc=9,
23 backlight=12,
24 rotation=270,
25 spi_speed_hz=10000000
26)
27
28# Initialize display.
29disp.begin()
30
31# Width and height to calculate text position.
32WIDTH = disp.width
33HEIGHT = disp.height
34
35# New canvas to draw on.
36img = Image.new('RGB', (WIDTH, HEIGHT), color=(0, 0, 0))
37draw = ImageDraw.Draw(img)
38
39# Text settings.
40font_size = 25
41font = ImageFont.truetype("fonts/Asap/Asap-Bold.ttf", font_size)
42text_colour = (255, 255, 255)
43back_colour = (0, 170, 170)
44
45message = "Hello, World!"
46size_x, size_y = draw.textsize(message, font)
47
48# Calculate text position
49x = (WIDTH - size_x) / 2
50y = (HEIGHT / 2) - (size_y / 2)
51
52# Draw background rectangle and write text.
53draw.rectangle((0, 0, 160, 80), back_colour)
54draw.text((x, y), message, font=font, fill=text_colour)
55disp.display(img)
56
57# Keep running.
58try:
59 while True:
60 pass
61
62# Turn off backlight on control-c
63except KeyboardInterrupt:
64 disp.set_backlight(0)