Dot Matrixとは,点(ドット)によるパターンのことで,電子デバイスでよく使われています.
この記事では,ドットでASCII制御文字を表示させるためのソースコードをメモします.
引用: [Arduinoでドットマトリクス表示 Part1 基本表示](https://programresource.net/2020/03/05/3075.html)出力画像
バイナリデータ
さしあたりpythonで扱える記述にしています.
ソースはこちらから拝借したものを加工しました.
dot_matrix_list = [
[0b0000000,0b0000000,0b0000000,0b0000000,0b0000000], # space
[0b0000000,0b0000000,0b1001111,0b0000000,0b0000000], # !
[0b0000000,0b0000111,0b0000000,0b0000111,0b0000000], # "
[0b0010100,0b1111111,0b0010100,0b1111111,0b0010100], # #
[0b0100100,0b0101010,0b1111111,0b0101010,0b0010010], # $
[0b0100011,0b0010011,0b0001000,0b1100100,0b1100010], # %
[0b0110110,0b1001001,0b1010101,0b0100010,0b1010000], # &
[0b0000000,0b0000101,0b0000011,0b0000000,0b0000000], # '
[0b0000000,0b0011100,0b0100010,0b1000001,0b0000000], # (
[0b0000000,0b1000001,0b0100010,0b0011100,0b0000000], # )
[0b0010100,0b0001000,0b0111110,0b0001000,0b0010100], # *
[0b0001000,0b0001000,0b0111110,0b0001000,0b0001000], # +
[0b0000000,0b1010000,0b0110000,0b0000000,0b0000000], # ,
[0b0001000,0b0001000,0b0001000,0b0001000,0b0001000], # -
[0b0000000,0b1100000,0b1100000,0b0000000,0b0000000], # .
[0b0100000,0b0010000,0b0001000,0b0000100,0b0000010], # /
[0b0111110,0b1010001,0b1001001,0b1000101,0b0111110], # 0
[0b0000000,0b1000010,0b1111111,0b1000000,0b0000000], # 1
[0b1000010,0b1100001,0b1010001,0b1001001,0b1000110], # 2
[0b0100001,0b1000001,0b1000101,0b1001011,0b0110001], # 3
[0b0011000,0b0010100,0b0010010,0b1111111,0b0010000], # 4
[0b0100111,0b1000101,0b1000101,0b1000101,0b0111001], # 5
[0b0111100,0b1001010,0b1001001,0b1001001,0b0110000], # 6
[0b0000011,0b1110001,0b0001001,0b0000101,0b0000011], # 7
[0b0110110,0b1001001,0b1001001,0b1001001,0b0110110], # 8
[0b0000110,0b1001001,0b1001001,0b0101001,0b0011110], # 9
[0b0000000,0b1101100,0b1101100,0b0000000,0b0000000], # :
[0b0000000,0b1010110,0b0110110,0b0000000,0b0000000], # ;
[0b0001000,0b0010100,0b0100010,0b1000001,0b0000000], # <
[0b0010100,0b0010100,0b0010100,0b0010100,0b0010100], # =
[0b0000000,0b1000001,0b0100010,0b0010100,0b0001000], # >
[0b0000010,0b0000001,0b1010001,0b0001001,0b0000110], # ?
[0b0110010,0b1001001,0b1111001,0b1000001,0b0111110], # @
[0b1111110,0b0010001,0b0010001,0b0010001,0b1111110], # A
[0b1111111,0b1001001,0b1001001,0b1001001,0b0111110], # B
[0b0111110,0b1000001,0b1000001,0b1000001,0b0100010], # C
[0b1111111,0b1000001,0b1000001,0b1000001,0b0111110], # D
[0b1111111,0b1001001,0b1001001,0b1001001,0b1001001], # E
[0b1111111,0b0001001,0b0001001,0b0001001,0b0000001], # F
[0b0111110,0b1000001,0b1001001,0b1001001,0b0111010], # G
[0b1111111,0b0001000,0b0001000,0b0001000,0b1111111], # H
[0b1000001,0b1000001,0b1111111,0b1000001,0b1000001], # I
[0b0110000,0b1000001,0b1000001,0b0111111,0b0000001], # J
[0b1111111,0b0001000,0b0010100,0b0100010,0b1000001], # K
[0b1111111,0b1000000,0b1000000,0b1000000,0b1000000], # L
[0b1111111,0b0000010,0b0001100,0b0000010,0b1111111], # M
[0b1111111,0b0000100,0b0001000,0b0010000,0b1111111], # N
[0b0111110,0b1000001,0b1000001,0b1000001,0b0111110], # O
[0b1111111,0b0001001,0b0001001,0b0001001,0b0000110], # P
[0b0111110,0b1000001,0b1010001,0b0100001,0b1011110], # Q
[0b1111111,0b0001001,0b0001001,0b0011001,0b1100110], # R
[0b1000110,0b1001001,0b1001001,0b1001001,0b0110001], # S
[0b0000001,0b0000001,0b1111111,0b0000001,0b0000001], # T
[0b0111111,0b1000000,0b1000000,0b1000000,0b0111111], # U
[0b0001111,0b0110000,0b1000000,0b0110000,0b0001111], # V
[0b0111111,0b1000000,0b0111000,0b1000000,0b0111111], # W
[0b1100011,0b0010100,0b0001000,0b0010100,0b1100011], # X
[0b0000011,0b0000100,0b1111000,0b0000100,0b0000011], # Y
[0b1100001,0b1010001,0b1001001,0b1000101,0b1000011], # Z
[0b1111111,0b1000001,0b1000001,0b0000000,0b0000000], # [
[0b0000010,0b0000100,0b0001000,0b0010000,0b0100000], # '\'
[0b0000000,0b0000000,0b1000001,0b1000001,0b1111111], # ]
[0b0000100,0b0000010,0b0000001,0b0000010,0b0000100], # ^
[0b1000000,0b1000000,0b1000000,0b1000000,0b1000000], # _
[0b0000000,0b0000001,0b0000010,0b0000100,0b0000000], # `
[0b0100000,0b1010100,0b1010100,0b1010100,0b1111000], # a
[0b1111111,0b1001000,0b1000100,0b1000100,0b0111000], # 0b
[0b0111000,0b1000100,0b1000100,0b1000100,0b0100000], # c
[0b0111000,0b1000100,0b1000100,0b1001000,0b1111111], # d
[0b0111000,0b1010100,0b1010100,0b1010100,0b0011000], # e
[0b0001000,0b1111110,0b0001001,0b0000001,0b0000010], # f
[0b0001100,0b1010010,0b1010010,0b1010010,0b0111110], # g
[0b1111111,0b0001000,0b0000100,0b0000100,0b1111000], # h
[0b0000000,0b1000100,0b1111101,0b1000000,0b0000000], # i
[0b0100000,0b1000000,0b1000100,0b0111101,0b0000000], # j
[0b1111111,0b0010000,0b0101000,0b1000100,0b0000000], # k
[0b0000000,0b1000001,0b1111111,0b1000000,0b0000000], # l
[0b1111000,0b0000100,0b0001000,0b0000100,0b1111000], # m
[0b1111100,0b0001000,0b0000100,0b0000100,0b1111000], # n
[0b0111000,0b1000100,0b1000100,0b1000100,0b0111000], # o
[0b1111100,0b0010100,0b0010100,0b0010100,0b0001000], # p
[0b0001000,0b0010100,0b0010100,0b1111100,0b0000000], # q
[0b1111100,0b0001000,0b0000100,0b0000100,0b0001000], # r
[0b1001000,0b1010100,0b1010100,0b1010100,0b0100000], # s
[0b0000100,0b0111111,0b1000100,0b1000000,0b0100000], # t
[0b0111100,0b1000000,0b1000000,0b0100000,0b1111100], # u
[0b0011100,0b0100000,0b1000000,0b0100000,0b0011100], # v
[0b0111100,0b1000000,0b0110000,0b1000000,0b0111100], # w
[0b1000100,0b0101000,0b0010000,0b0101000,0b1000100], # x
[0b0001100,0b1010000,0b1010000,0b1010000,0b0111100], # y
[0b1000100,0b1100100,0b1010100,0b1001100,0b1000100], # z
[0b0000000,0b0001000,0b0110110,0b1000001,0b0000000], # [
[0b0000000,0b0000000,0b1111111,0b0000000,0b0000000], # |
[0b0000000,0b1000001,0b0110110,0b0001000,0b0000000], # ]
[0b0001000,0b0000100,0b0000100,0b0001000,0b0000100] # ~
] # characters[95]
描画コード
import matplotlib.pyplot as plt
import numpy as np
def binary_to_int_list(binary):
"""2進数を01のリストに変換"""
return [int(n_str) for n_str in list(format(binary, '07b'))]
int_matrix_list = [[binary_to_int_list(binary)
for binary in dot_matrix]
for dot_matrix in dot_matrix_list]
# 描画
fig, axes = plt.subplots(nrows=19, ncols=5, figsize=(7,30))
for i, int_matrix in enumerate(int_matrix_list):
row, col = i//5, i%5
axes[row,col].imshow(np.flipud(np.array(int_matrix).T), cmap='Greys', interpolation='nearest')
axes[row,col].tick_params(labelbottom=False, labelleft=False, labelright=False, labeltop=False,
bottom=False, left=False, right=False, top=False)
plt.savefig("DotMatrix.png")
plt.show()