-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwaveshare_example.py
More file actions
60 lines (52 loc) · 1.88 KB
/
Copy pathwaveshare_example.py
File metadata and controls
60 lines (52 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys
import os
picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic')
libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
if os.path.exists(libdir):
sys.path.append(libdir)
import logging
import time
import traceback
from waveshare_OLED import OLED_0in91
from PIL import Image,ImageDraw,ImageFont
logging.basicConfig(level=logging.DEBUG)
try:
disp = OLED_0in91.OLED_0in91()
logging.info("\r0.91inch OLED Module ")
# Initialize library.
disp.Init()
# Clear display.
logging.info("clear display")
disp.clear()
# Create blank image for drawing.
image1 = Image.new('1', (disp.width, disp.height), "WHITE")
draw = ImageDraw.Draw(image1)
font1 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 12)
font2 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18)
logging.info ("***draw line")
draw.line([(0,0),(127,0)], fill = 0)
draw.line([(0,0),(0,31)], fill = 0)
draw.line([(0,31),(127,31)], fill = 0)
draw.line([(127,0),(127,31)], fill = 0)
logging.info ("***draw text")
draw.text((20,0), 'Waveshare ', font = font1, fill = 0)
draw.text((20,12), u'微雪电子 ', font = font2, fill = 0)
image1=image1.rotate(0)
disp.ShowImage(disp.getbuffer(image1))
time.sleep(3)
logging.info ("***draw image")
Himage2 = Image.new('1', (disp.width, disp.height), 255) # 255: clear the frame
bmp = Image.open(os.path.join(picdir, '0in91.bmp'))
Himage2.paste(bmp, (0,0))
Himage2=Himage2.rotate(0)
disp.ShowImage(disp.getbuffer(Himage2))
time.sleep(3)
disp.clear()
except IOError as e:
logging.info(e)
except KeyboardInterrupt:
logging.info("ctrl + c:")
disp.module_exit()
exit()