esp32 + MicroPython 实现数码管显示数字

Posted 刘润森!

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了esp32 + MicroPython 实现数码管显示数字相关的知识,希望对你有一定的参考价值。

学习来源: 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)

数码管显示数字

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()



esp32 + MicroPython 实现数码管显示数字

来源:https://doc.itprojects.cn/0006.zhishi.esp32/02.doc/index.html#/

以上是关于esp32 + MicroPython 实现数码管显示数字的主要内容,如果未能解决你的问题,请参考以下文章

esp32 + MicroPython 实现数码管显示数字

esp32 cam+esp8266用micropython实现人脸识别开门

酷易物联-microPython教程系列通过文件模板将ESP32连入服务器实现远程点灯:让ESP32连接服务器实现远程开关灯

酷易物联-microPython教程系列通过文件模板将ESP32连入服务器实现远程点灯:让ESP32连接服务器实现远程开关灯

酷易物联-microPython教程系列通过文件模板将ESP32连入服务器实现远程点灯:让ESP32连接服务器实现远程开关灯

MicroPython ESP32 入网和udp数据收发通讯示例