esp32 + MicroPython 实现数码管显示数字
【摘要】
学习来源: https://doc.itprojects.cn/0006.zhishi.esp32/02.doc/index.html#/README
环境搭建
https://doc.itproje...
学习来源: https://doc.itprojects.cn/0006.zhishi.esp32/02.doc/index.html#/README
环境搭建
https://doc.itprojects.cn/0006.zhishi.esp32/02.doc/index.html#/01.dajianhuanjing
使用thonny烧录MicroPython固件失败,
点亮LED灯
from machine import Pin
pin2 = Pin(2, Pin.OUT)
pin2.value(1)
- 1
- 2
- 3
- 4
数码管显示数字
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)
dot = machine.Pin(32, machine.Pin.OUT)
number_led = [a, b, c, d, e, f, g, dot]
number_dict = {
0: "11111100",
1: "01100000",
2: "11011010",
3: "11110010",
4: "01100110",
5: "10110110",
6: "10111110",
7: "11100000",
8: "11111110",
9: "11110110",
"open": "11111111",
"close": "00000000"
}
def show_number(number):
if number_dict.get(number):
i = 0
for bit in number_dict.get(number):
if bit == "1":
number_led[i].value(1)
else:
number_led[i].value(0)
i += 1
def main():
show_number("open") # 全亮
time.sleep(2)
show_number("close") # 全灭
for i in range(10):
show_number(i)
time.sleep(1)
if __name__ == "__main__":
main()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
esp32 + MicroPython 实现数码管显示数字
来源:https://doc.itprojects.cn/0006.zhishi.esp32/02.doc/index.html#/
文章来源: maoli.blog.csdn.net,作者:刘润森!,版权归原作者所有,如需转载,请联系作者。
原文链接:maoli.blog.csdn.net/article/details/125772507
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)