一、数码管介绍
1.数码管图片
2.数码管为什么会亮?
里面就是LED灯
3.数码管的管脚图和共阴极共阳极图片
二、连接方式
我使用的是共阳极数码管连接方式如下。
三、代码
import machine
import time
a = machine.Pin(13, machine.Pin.OUT)
b = machine.Pin(12, machine.Pin.OUT)
c = machine.Pin(14, machine.Pin.OUT)
d = machine.Pin(27, machine.Pin.OUT)
e = machine.Pin(26, machine.Pin.OUT)
f = machine.Pin(25, machine.Pin.OUT)
g = machine.Pin(33, machine.Pin.OUT)
h = machine.Pin(32, machine.Pin.OUT)
# 将对应的引脚对象存储到列表
led_list = [a, b, c, d, e, f, g, h]
number_dict = {
0: "00000011", # 顺序依次是abcdefgh
1: "10011111",
2: "00100101",
3: "00001101",
4: "10011001",
5: "01001001",
6: "01000001",
7: "00011111",
8: "00000001",
9: "00001001"
}
def show_number(number):
if number_dict.get(number): # 如果取出的值在字典中
i = 0
for num in number_dict.get(number):
if num == "1":
led_list[i].value(1)
else:
led_list[i].value(0)
i += 1
if __name__ == "__main__":
while True:
for i in range(0, 10):
show_number(i)
time.sleep(1)