【发布时间】:2019-06-03 16:51:33
【问题描述】:
我在主函数中有一个爆震传感器,它运行下一个函数,在下一个函数中我使用了 irq()。但在第二个函数中不能工作 irq。怎么修???还是用其他方式??
我希望设备处于待机模式并通过敲击运行 enter_password() 函数。 敲一敲,enter_password() 启动。完成后进入待机模式,等待新敲门再次运行 enter_password()。
敲一次必须运行 enter_password() 并通过 5 次循环从用户那里获取密码。每一次循环给出 1 或 2 或 ...或 9 次敲门。
例如: 1knock >> 运行应用程序 >> 运行 enter_password()
for i range 4 >> 5 循环
loop 1 >>1knock >>my pass >> 1
loop 2 >> 7knock >>my pass >> 17
loop3 >> 4knock >>my pass >> 174
loop 4 >> 0knock >>my pass >> 1740
loop 5 >> 2knock >>my pass >> 17402
我的通行证>> 17402
if ok >> 通过我的数据库中的另一个函数打开门#serach 并返回 ok 或 not ok 其他>>什么都没有
然后进入待机状态,等待 1 次敲门声以一次又一次地运行应用程序。
我在 nodemcu 上使用 micropython。 tnx 帮帮我
num_knock = 0
def main():
.
.
.
while True:
P5 = Pin(5, Pin.IN)
P5.irq(trigger=Pin.IRQ_RISING , handler=enter_password() ) //ONE IRQ
def enter_password(P):
print("enter password starting")
p5 = Pin(5, Pin.IN)
door_password=""
for i in range(5):
global num_knock
num_knock = 0
chk_time = utime.time() + 12
while utime.time() <= chk_time:
p5.irq(trigger=Pin.IRQ_RISING , handler=callback ) #TWO IRQ - BUT NOT WORK - not call callback
door_password += str(num_knock )
return
def callback(p):
global num_knock
if num_knock < 9 :
num_knock += 1
led_num_knock = Pin(4, Pin.OUT)
led_num_knock.on()
utime.sleep_ms(200)
led_num_knock.off()
return
【问题讨论】:
-
为 pin 设置一次 IRQ,然后循环运行,而不是使用单独的函数。
标签: python nodemcu micropython