https://make-muda.net/2015/01/2414/
さんのホームページを参考にして、
HT16K33を使用した、8x8 matrix led
4個でのスクロールを試してみた
[sample script]
#!/usr/bin/env python3
import time
import board
import busio
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
from adafruit_ht16k33 import matrix
# Referenced https://make-muda.net/2015/01/2414/
def horizontal_multi_scroll(matrix, image, total=1, number=0):
padding=True
image_list = list()
width = image.size[0]
for x in range(matrix.columns * number):
display_section = create_blank_image(matrix)
image_list.append(display_section)
# Scroll into the blank image.
if padding:
for x in range(matrix.columns):
section = image.crop((0, 0, x, matrix.rows))
display_section = create_blank_image(matrix)
display_section.paste(section, (matrix.columns - x, 0, matrix.columns, matrix.rows))
image_list.append(display_section)
#Scroll across the input image.
for x in range(matrix.columns, width + 1):
section = image.crop((x - matrix.columns, 0, x, matrix.rows))
display_section = create_blank_image(matrix)
display_section.paste(section, (0, 0, matrix.columns, matrix.rows))
image_list.append(display_section)
#Scroll out, leaving the blank image.
if padding:
for x in range(width - matrix.columns - 1, width + 1):
section = image.crop((x, 0, width, matrix.rows))
display_section = create_blank_image(matrix)
display_section.paste(section, (0, 0, (matrix.columns - 1) - (x - (width - (matrix.columns - 1))), matrix.rows))
image_list.append(display_section)
for x in range(matrix.columns * (total - (number + 1))):
display_section = create_blank_image(matrix)
image_list.append(display_section)
#Return the list of images created
return image_list
def create_blank_image(matrix):
return Image.new("RGB", (matrix.columns, matrix.rows))
# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)
# Create the matrix class.
matrixx=[]
i2c_address=(0x71, 0x70,)
for addr in i2c_address:
matrixx.append(matrix.Matrix16x8(i2c, address=addr))
text = "ぎおんしょうじゃのかねのこえ しょぎょうむじょうのひびきあり さらそうじゅのはなのいろ じょう しゃひっすいのことわりをあらわす おごれるひともひさしからず ただはるのよのゆめのごとし たけきもの もついにはほろびぬ ひとえにかぜのまえのちりにおなじ"
text_len = len(text)
image = Image.new('1', (text_len*8, 8))
draw = ImageDraw.Draw(image)
font = ImageFont.truetype("/home/pi/font/misakifont/misaki_gothic.ttf", 8, encoding='unic')
draw.text((0,1), text, font=font, fill=255)
new_image = image.transpose(Image.FLIP_TOP_BOTTOM)
image_listx = []
max_addr=len(i2c_address)
for i in range(0, max_addr):
image_listx.append( horizontal_multi_scroll(matrixx[0], new_image, max_addr, i))
max_images = len(image_listx[0])
while True:
for i in range(0, max_images):
for j, m in enumerate(matrixx, 0):
m.image(image_listx[j][i])
※
i2c_address=(0x71, 0x70,)の部分を
i2c_address=(0x70,) とかにすると
16x8 で動きますね
0 件のコメント:
コメントを投稿