#author("2020-06-03T00:39:48+09:00","default:TeleportDresser","TeleportDresser")
[[TeleportDresser]]

#code(Python){{

# coding: utf-8
from PIL import Image
import smbus
import time
import sys
import requests

off_x=0
off_y=0

imax=75
jmax=16

print( 'number of arguments:', len(sys.argv), 'arguments.')
arglist = sys.argv
print( 'Argument List:', sys.argv)
url=arglist[1]
print( 'url=', url)
#url = "url of the target image"
if url.endswith(".jpg"):
    file_name = "ex3.jpg"
elif url.endswith(".png"):
    file_name = "ex3.png"
elif url.endswith(".svg"):
    file_name = "ex3.svg"
elif url.endswith(".JPG"):
    file_name = "ex3.jpg"
elif url.endswith(".PNG"):
    file_name = "ex3.png"
response = requests.get(url)
image = response.content
with open(file_name, "wb") as aaa:
    aaa.write(image)

img = Image.open(file_name)
img_width, img_height = img.size
print('width:',img_width)
print('height:',img_height)

dx=img_width/jmax
dy=img_height/imax

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=[[(0,0,0) for j in range(jmax)] for i in range(imax)]
          
addrs = [0x30,0x31,0x32,0x33]
fourpix=[0x00, 0x00, 0x04, 0,0,0, 0,0,0, 0,0,0, 0,0,0]
for i in range(imax):
    for j in range(jmax):
        x=off_x+j*dx
        y=off_y+i*dy
        rgb=img.getpixel((x,y))
        pixels[i][j]=rgb

i2c.write_byte(addrs[0],0x00)
i2c.write_byte(addrs[1],0x00)
i2c.write_byte(addrs[2],0x00)
i2c.write_byte(addrs[3],0x00)
for i in range(imax):
  for j in range(4):
    for k in range(4):
      p=pixels[i][4*j+k]
      fourpix[3+k*3+0]=p[0]
      fourpix[3+k*3+1]=p[1]
      fourpix[3+k*3+2]=p[2]
    fourpix[0]=i;
    fourpix[1]=0;
    i2c_addr=addrs[j]
    try:
      i2c.write_i2c_block_data(i2c_addr,0x03,fourpix)
    except:
      print('i2c write error at:(',i,',',j,')')
    time.sleep(0.0005)
i2c.write_byte(addrs[0],0x01)
i2c.write_byte(addrs[1],0x01)
i2c.write_byte(addrs[2],0x01)
i2c.write_byte(addrs[3],0x01)

}}

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS