#author("2020-06-03T00:32:04+09:00","default:TeleportDresser","TeleportDresser") [[TeleportDresser]] #code(Python){{ import smbus import time i2c = smbus.SMBus(1) # 注:ラズパイのI2Cポート # # command: # clear... 0x00 # show ... 0x01 # set1 ix,iy,r,g,b # ... 0x02 *,*, *,*,* # setn ix,iy,n, r0,g0,b0, ..r(n-1),g(n-1),b(n-1) n<=8 # ... 0x03 *,*, *, *,*,*, ..., *,*,* # 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) }}