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
|
-
|
|
|
|
|
|
|
|
!
| import smbus
import time
i2c = smbus.SMBus(1) pixels= [ \
[ ' ',' ',' ',' ',' ',' ',' ',' '],\
[ ' ','r','r',' ',' ','r','r',' '],\
[ 'r',' ',' ','r','r',' ',' ','r'],\
[ 'r',' ',' ',' ',' ',' ',' ','r'],\
[ 'r',' ',' ',' ',' ',' ',' ','r'],\
[ 'r',' ',' ',' ',' ',' ',' ','r'],\
[ ' ','r',' ',' ',' ',' ','r',' '],\
[ ' ','r',' ',' ',' ',' ','r',' '],\
[ ' ',' ','r',' ',' ','r',' ',' '],\
[ ' ',' ',' ','r','r',' ',' ',' '],\
[ ' ',' ',' ',' ',' ',' ',' ',' '],\
[ ' ','g','g','g','g','g','g','g'],\
[ ' ',' ','g','y','y','y','g',' '],\
[ ' ',' ',' ','g','y','g',' ',' '],\
[ ' ',' ',' ','g','y','g',' ',' '],\
[ ' ',' ',' ',' ','g',' ',' ',' '] ]
addrs = [0x30,0x31]
fourpix=[0x00, 0x00, 0x04, 0,0,0, 0,0,0, 0,0,0, 0,0,0]
r_comp={' ':0x00, 'r':0xff, 'g':0x00, 'b':0x00, 'y':0xff, 'w':0xff}
g_comp={' ':0x00, 'r':0x00, 'g':0xff, 'b':0x00, 'y':0xff, 'w':0xff}
b_comp={' ':0x00, 'r':0x00, 'g':0x00, 'b':0xff, 'y':0x00, 'w':0xff}
i2c.write_byte(0x30,0x00)
i2c.write_byte(0x31,0x00)
for i in range(16):
for j in range(2):
for k in range(4):
p=pixels[i][4*j+k]
for color in ['r','g','b']:
if color == 'r':
fourpix[3+k*3+0]=r_comp[p]
elif color == 'g':
fourpix[3+k*3+1]=g_comp[p]
elif color == 'b':
fourpix[3+k*3+2]=b_comp[p]
fourpix[0]=i;
fourpix[1]=0;
i2c_addr=addrs[j]
i2c.write_i2c_block_data(i2c_addr,0x03,fourpix)
time.sleep(0.005)
i2c.write_byte(addrs[0],0x01)
i2c.write_byte(addrs[1],0x01)
|