起因:micropython 中驱动oled
没有中文字库所以写了几行代码来解决这个问题
python代码:
def getu(_):
code = 0x00
_ = _.encode("utf-8")
code |= (_[0] << 16)
code |= (_[1] << 8)
code |= (_[2])
return hex(code)
f = open("字.txt","r") #设置文件对象
lines=f.readlines()
a=int(len(lines)/2)
for i in range(a):
line1 = getu(lines[i*2+1][79])+":"
line2 = "["+lines[i*2][:-1]+","
line3 = " "+lines[i*2+1][:79] +"],#"+lines[i*2+1][79]
print(line1)
print(line2)
print(line3)
f.close()
使用方法:
先打开取模工具:
选项如图配置:
输入中文:
生成字模:
复制下面的文字到一个txt文件中如图:
(前面没有空格)
运行脚本