返回

八、控制8x8点阵屏

esp32

1. 说明

1.1 引脚图

大家从王老师淘宝店铺购买的ESP32学习套装中的8x8点阵屏,说明如下

  • 购买的8x8点阵是单色的,即纯红色
  • 引脚上下2排,每排8根

引脚的说明如下

1655183960598

上图中

  • C表示column 列的意思,所有的C接高电压,即控制esp32中输出1
  • L表示line 行的意思,所有的L接低电压,即控制esp32中输出为0

1.2 怎样区分前后?

image-20231229164924085

1.3 怎样快速上手,怎样接线?

下图,让你用1分钟,快速让8x8点阵 亮起1个LED灯

image-20231229165849722

注意:务必串联1个200~300欧姆的电阻,否则烧坏器件

image-20231229170211949

说明:

  • 上图ESP323.3v连接线通过1个220欧姆的电阻连接到 8x8点阵C7那个引脚
  • 上图ESP32GND连接到8x8点阵L5引脚
  • 如果连接一切正常,那么会看到从上往下数第5行,从左往右数第7列那个LED灯亮
  • 上图串联的是220欧姆的电阻,怎样从电阻包中找到合适的电阻呢?看电阻纸袋上的文字,例如220R就是220欧姆的意思,如果没有220R,不要较真,找个200~300之间的都行
    image-20231229173416985

2. 点阵屏引脚

image-20231229172311157

3. 链接图

image-20231229172132979

4. 代码

import machine
import time

row_1 = machine.Pin(32, machine.Pin.OUT)
row_2 = machine.Pin(33, machine.Pin.OUT)
row_3 = machine.Pin(25, machine.Pin.OUT)
row_4 = machine.Pin(26, machine.Pin.OUT)
row_5 = machine.Pin(27, machine.Pin.OUT)
row_6 = machine.Pin(14, machine.Pin.OUT)
row_7 = machine.Pin(12, machine.Pin.OUT)
row_8 = machine.Pin(13, machine.Pin.OUT)

row_list = [row_1, row_2, row_3, row_4, row_5, row_6, row_7, row_8]


col_1 = machine.Pin(19, machine.Pin.OUT)
col_2 = machine.Pin(18, machine.Pin.OUT)
col_3 = machine.Pin(5, machine.Pin.OUT)
col_4 = machine.Pin(17, machine.Pin.OUT)
col_5 = machine.Pin(16, machine.Pin.OUT)
col_6 = machine.Pin(4, machine.Pin.OUT)
col_7 = machine.Pin(2, machine.Pin.OUT)
col_8 = machine.Pin(15, machine.Pin.OUT)

col_list = [col_1, col_2, col_3, col_4, col_5, col_6, col_7, col_8]


def set_power_row(i):
    for row in row_list:
        row.value(0)
    if 0 <= i <= 7:
        row_list[i].value(1)


def set_earth_col(i):
    for col in col_list:
        col.value(1)
    if 0 <= i <= 7:
        col_list[i].value(0)


def show_liushuideng():
    # 流水灯
    for row in range(8):
        set_power_row(row)
        for col in range(8):
            set_earth_col(col)
            time.sleep_ms(100)

def show_arrow():
    # 箭头图形
    img_list = [
        (1, 4),
        (2, 5),
        (3, 6),
        (4, 0), (4, 1), (4, 2), (4, 3), (4, 4), (4, 5), (4, 6), (4, 7),
        (5, 6),
        (6, 5),
        (7, 4)
    ]

    # 让箭头从左向右移动
    while True:
        for i in range(-7, 8):
            for j in range(5):
                for x, y in img_list:
                    set_power_row(x)
                    set_earth_col(y + i)
                    time.sleep_ms(1)

if __name__ == "__main__":
    show_liushuideng()
    show_arrow()

复制Error复制成功...