-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patheink2.13_demo.py
63 lines (52 loc) · 1.42 KB
/
eink2.13_demo.py
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
61
62
63
import time
from Epaper import *
from PIL import Image #Pillow
# Demo Configuration
X_PIXEL = 128
Y_PIXEL = 250
RED_CH = True # If the module has only two colors(B&W), please set it to False.
if RED_CH is True:
print("Flash Red")
e = Epaper(X_PIXEL,Y_PIXEL)
e.flash_red(on=True)
e.flash_black(on=False)
e.update()
time.sleep(1)
print("Flash Black")
e = Epaper(X_PIXEL,Y_PIXEL)
if RED_CH is True:
e.flash_red(on=False)
e.flash_black(on=True)
e.update()
time.sleep(1)
print("Flash White")
e = Epaper(X_PIXEL,Y_PIXEL)
if RED_CH is True:
e.flash_red(on=False)
e.flash_black(on=False)
e.update()
time.sleep(1)
print("Flash Image")
f = Image.open('demo.png')
f = f.convert('RGB') # conversion to RGB
data = f.load()
rBuf = [0] * 4000
bBuf = [0] * 4000
for y in range(250):
for x in range(128):
# Red CH
if data[x,y] == (237,28,36) and RED_CH is True:
# This algorithm has bugs if ported according to C, the solution is referred to:https://www.taterli.com/7450/
index = int(16 * y + (15 - (x - 7) / 8))
tmp = rBuf[index]
rBuf[index] = tmp | (1 << (x % 8))
# Black CH
elif data[x,y] == (255,255,255):
index = int(16 * y + (15 - (x - 7) / 8))
tmp = bBuf[index]
bBuf[index] = tmp | (1 << (x % 8))
e = Epaper(X_PIXEL,Y_PIXEL)
if RED_CH is True:
e.flash_red(buf=rBuf)
e.flash_black(buf=bBuf)
e.update()