如何在 LED 矩阵中滚动内容 (Raspberry Pi / Python 3)

How to scroll something through an LED matrix (Raspberry Pi / Python 3)

我安排了一个可单独寻址的 LED 矩阵 (12x12)。我还写下了当我想要显示某个字母时必须点亮哪些 LED 的模式,如下所示:

letter_a = ['00111100', '01000010', '01000010', '01111110', '01000010', '01000010', '01000010', '01000010']

而且我可以毫无问题地显示它。我想要完成的是让这些模式从右到左滚动矩阵,这样人们就可以在本质上是滚动的 144 像素显示屏上阅读文本。

我的问题是我对编程还很陌生,不知道如何摆脱将每个像素寻址到某个 LED 而不是将图案作为一个整体来处理 - 无论它在矩阵的哪个位置应该会亮起 - 这样我就可以移动它了。

我建议您将 LED 的状态保持在结构类似于 letter_a 的 'frame' 中。这将允许您轻松修改它并根据需要重新显示它。

之后,每次有动作时,只需编辑框架即可。你可以这样做:

def nextFrame(current_frame, queue):
    for row in range(0, len(current_frame)):
        new_row = current_frame[row][1:] + queue[row][0]
        current_frame[row] = new_row
        queue[row] = queue[row][1:]
    return current_frame, queue

你可以使用这样的东西:

letter_a = ['00111100', '01000010', '01000010', '01111110', '01000010', '01000010', '01000010', '01000010']
current_frame = ['10000001', '01000010', '00100100', '00011000', '00011000', '00100100', '01000010', '10000001']
queue = ['00111100', '01000010', '01000010', '01111110', '01000010', '01000010', '01000010', '01000010']
while len(queue[0]):
    display(current_frame)
    current_frame, queue = nextFrame(current_frame, queue)