from machine import Pin
import time
import network
import urequests
#数码管练习
a = Pin(5,Pin.OUT)
b = Pin(18,Pin.OUT)
c = Pin(22,Pin.OUT)
d = Pin(21,Pin.OUT)
e = Pin(19,Pin.OUT)
f = Pin(4,Pin.OUT,value=1)
g = Pin(15,Pin.OUT)
dp = Pin(23,Pin.OUT)
# Common --> Anode: 0点亮,1熄灭
segments = [a,b,c,d,e,f,g,dp]
# 数字表格且dp常暗(阳极)
SEG_TABLE = {
0: [0, 0, 0, 0, 0, 0, 1, 1],
1: [1, 0, 0, 1, 1, 1, 1, 1],
2: [0, 0, 1, 0, 0, 1, 0, 1],
3: [0, 0, 0, 0, 1, 1, 0, 1],
4: [1, 0, 0, 1, 1, 0, 0, 1],
5: [0, 1, 0, 0, 1, 0, 0, 1],
6: [0, 1, 0, 0, 0, 0, 0, 1],
7: [0, 0, 0, 1, 1, 1, 1, 1],
8: [0, 0, 0, 0, 0, 0, 0, 1],
9: [0, 0, 0, 0, 1, 0, 0, 1],
} # dp默认熄灭
def show_digit(num, show_dp=False):
if num not in SEG_TABLE:
return
else:
pattern = SEG_TABLE[num].copy()
pattern[7] = 0 if show_dp else 1
for pin, val in zip(segments, pattern):
pin.value(val)
def clear():
"""熄灭所有段"""
for pin in segments:
pin.value(1) # 共阳极:1 为灭
clear()
while True:
for i in range(9,-1,-1):
show_digit(i,True)
time.sleep(1)
'''
#在有限范围内进行闪烁
lu_pin = Pin(2,Pin.OUT)
start_time = time.time()
duration = 10 #持续时间定义
while time.time() - start_time <= duration:
lu_pin.on()
time.sleep(0.5)
lu_pin.off()
time.sleep(0.5)
lu_pin.value(0)
print('时间已到,停止闪烁')
'''
'''
# 按钮控制LED亮灭
lu_pin = Pin(2,Pin.OUT,value=0)
lu_button = Pin(14,Pin.IN, Pin.PULL_DOWN)
def button_irq(lu_button):
time.sleep_ms(10)
if lu_button.value() == 1:
lu_pin.value(not lu_pin.value())
lu_button.irq(button_irq,Pin.IRQ_RISING)
'''
'''
status = 0
while True:
if lu_button.value() == 1:
time.sleep_ms(80) #消抖延时
if lu_button.value() == 1 and status == 0:
lu_pin.value(not lu_pin.value()) #直接去反
status = 1
else:
status = 0
while True:
lu_pin.on()
time.sleep(0.5)
lu_pin.off()
time.sleep(0.5)
'''Loading
esp32-devkit-c-v4
esp32-devkit-c-v4