#author("2020-06-03T00:29:25+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',' ',' ',' ','g',' '],\ [ ' ',' ',' ','g',' ','g',' ',' '],\ [ ' ',' ',' ','g',' ','g',' ',' '],\ [ ' ',' ',' ',' ','g',' ',' ',' '] ] addrs = [0x30,0x31] i2c.write_byte(0x30,0x00) i2c.write_byte(0x31,0x00) for i in range(16): for j in range(8): p=pixels[i][j] if p!=' ' : if p=='r': r=0xff g=0x00 b=0x00 elif p=='g': r=0x00 g=0xff b=0x00 elif p=='b': r=0x00 g=0x00 b=0xff if j<4: i2c_addr=addrs[0] cmd=[i,j,r,g,b] else: i2c_addr=addrs[1] cmd=[i,j-4,r,g,b] i2c.write_i2c_block_data(i2c_addr,0x02,cmd) i2c.write_byte(addrs[0],0x01) i2c.write_byte(addrs[1],0x01) }}