首页 > 解决方案 > 如何在 irq() 中运行 irq() ?或在第二个 irq 上禁用一个 irq?

问题描述

我在主要功能中有一个爆震传感器,它运行下一个功能,在下一个功能中我使用了 irq()。但在 secend 功能中不能使用 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

循环 2 >> 7knock >> 我的传球 >> 17

loop3 >> 4knock >>my pass >> 174

循环 4 >> 0knock >> 我的通行证 >> 1740

循环 5 >> 2knock >> 我的通行证 >> 17402

我的通行证 >> 17402

if ok >> open door #serach by another function in my db and return ok or not ok else >> nothing

并进入待机状态并等待 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

标签: pythonnodemcumicropython

解决方案



def main():
    starter = Pin(5, Pin.IN)
    webserver()
    while True:
        if starter.value()==1:   #use while anf if for one IRQ
            print("enter password fun")
            led_on_off(3,600)
            p5 = Pin(5, Pin.IN)
            door_password=""
            for i in range(5):
                print("range %i" %i)
                global num_kenok
                num_kenok = 0
                chk_time = utime.time() + 12
                while utime.time() <= chk_time:
                    p5.irq(trigger=Pin.IRQ_RISING ,  handler=callback )
                door_password += str(num_kenok)
                led_on_off(1,500)
            led_on_off(5,300)
            find_password(door_password)

推荐阅读