٤Ƴ٤Ĥ
  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
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
-
!
 
 
 
 
 
 
 
 
 
 
 
 
-
|
|
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
!
 
 
 
 
-
!
-
|
|
|
|
|
|
|
|
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
!
 
 
 
 
 
# coding: utf-8
from PIL import Image
import smbus
import time
import sys
import requests
import os
 
off_x=0
off_y=0
 
imax=75
jmax=16
 
#anime_pics_name=["anime-ex1_01.png","anime-ex1_02.png",
#            "anime-ex1_03.png","anime-ex1_04.png","anime-ex1_05.png"]
#anime_img=["","","","",""]
 
anime_img=[]
 
i2c = smbus.SMBus(1) # 注:ラズパイのI2Cポート
 
def main():
    print( 'number of arguments:', len(sys.argv), 'arguments.')
    arglist = sys.argv
    print( 'Argument List:', sys.argv)
    anime_dir=arglist[1]
    print( 'file_name(dir)=', anime_dir)
 
    try:
        anime_pics_name = os.listdir(anime_dir)
    except:
        anime_dir="/home/pi/Pictures/"
        anime_pics_name=["anime-ex1_01.png","anime-ex1_02.png",
            "anime-ex1_03.png","anime-ex1_04.png","anime-ex1_05.png"]
    pic_num=len(anime_pics_name)
    print(pic_num)
    print(anime_pics_name)
    anime_img = ["" for i in range(pic_num)]
    anime_pics_name.sort()
    for i in range(pic_num):
        pic_name = anime_dir+"/"+anime_pics_name[i]
        print(pic_name)
        #anime_img.appned(Image.open(pic_name))
        img = Image.open(pic_name)
        anime_img[i]=img
    for j in range(20):
        for i in range(pic_num):
            show_one_pic(anime_img[i])
            #time.sleep(0.1)
              
#
# 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]
          
def show_one_pic(img):
  img_width, img_height = img.size
  print('width:',img_width)
  print('height:',img_height)
 
  dx=img_width/jmax
  dy=img_height/imax
 
  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.00001)
  i2c.write_byte(addrs[0],0x01)
  i2c.write_byte(addrs[1],0x01)
  i2c.write_byte(addrs[2],0x01)
  i2c.write_byte(addrs[3],0x01)
 
main() 

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2020-06-03 (水) 22:18:30 (1413d)