【问题标题】:how run irq() in irq() ? or disable one irq on secend irq?如何在 irq() 中运行 irq() ?或在第二个 irq 上禁用一个 irq?
【发布时间】: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


【解决方案1】:

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)

【讨论】:

    猜你喜欢
    • 2018-08-14
    • 1970-01-01
    • 2019-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 2010-09-21
    相关资源
    最近更新 更多