用microbit控制16x16点阵屏显示汉字和图案

micro:bit编程、教学、展示
STEM
回复
头像
shaoziyang
帖子: 3917
注册时间: 2019年 10月 21日 13:48

用microbit控制16x16点阵屏显示汉字和图案

#1

帖子 shaoziyang »

这个程序是在台湾教育专家王老师(Alex)的程序基础上改进来的。

图片

代码: 全选

from microbit import *
from neopixel import NeoPixel

class neo16x16:
    def __init__(self, np):
        self.np = np
        self.color = (0,0,8)

    def clear(self):
        self.np.clear()

    def set(self, n, dat):
        self.np[n] = dat
        self.np.show()

    def color(self, color):
        self.color = color

    def show(self, dat, pos=0, clear = True, color=''):
        if color != '':
            self.color = color
        if clear:
            for i in range(256):
                self.np[i]=(0,0,0)
        for x in range(16):
            for y in range(16):
                if (x+pos)>=len(dat):
                    self.np[x*16+y]=(0,0,0)
                else:
                    if (1<<y)&dat[x+pos]:
                        if pos%2==0:
                            self.np[x*16 + y] = self.color
                        else:
                            self.np[x*16 +15 - y] = self.color

        self.np.show()

np = NeoPixel(pin16, 256)
ne = neo16x16(np)

dat=[
0x0440,0x2220,0x0654,0x2AC0,0xFFD4,0x2B7F,0x9274,0xFE49,
0x925F,0x2A49,0xFED4,0x2BFF,0x0354,0x2A60,0x0444,0x0220,
0x0000,0x2000,0x0044,0x2200,0x0044,0xFA00,0x005F,0x23FF,
0xFFC4,0x2200,0x0844,0xFA18,0x185F,0x23F0,0x07C4,0x2000,
0x0004,0x0000,0x0100,0x0780,0x00E0,0xFFFF,0xFFFF,0x0C81,
0xC128,0x108E,0x3D08,0xFFF0,0x0FFF,0x10BC,0x71F8,0x1F83,
0x8100,0x0081,0x0000,0x0000,0x2000,0x070C,0x18FC,0x3970,
0x4684,0x2103,0xFFF4,0x6FFE,0x0082,0xC140,0x0683,0x4130,
0x3880,0x010C,0x0000,0x0000,0x0000,0x0000,0x0000,0x1FCC,
0x33F8,
]

def _delay(t):
    while t>0:
        t = t - 1

n = 0
while True:
    ne.show(dat, n)
    n = (n + 1)%72
    _delay(100)


头像
shaoziyang
帖子: 3917
注册时间: 2019年 10月 21日 13:48

Re: 用microbit控制16x16点阵屏显示汉字和图案

#2

帖子 shaoziyang »

完整程序和工具请参考github上的社区驱动库

https://github.com/shaoziyang/microbit- ... /neo_16x16

回复

  • 随机主题
    回复总数
    阅读次数
    最新文章