python - 如何在 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
解决方案
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)
推荐阅读
- veins - 如何计算静脉中的 RSSI
- python - 从外部停止线程
- reactjs - 反应形式结合
- python - Python Pandas 使用匹配的列附加到现有的 excel
- firebase-realtime-database - 将数据从应用内配置文件传输到另一台服务器上的网络配置文件
- flutter - Flutter 显示变量的变化
- php - 不允许“闭包”的异常序列化
- java - 在非 root 的 Android 上通过 Termux Java SE 程序捕获数据包
- sql-server - 通过代理作业(作为代理/凭据运行)执行 SSIS 包时解决“意外终止”错误的最低权限是多少?
- database-connection - SQL Developer 连接未打开且 TNS 文件未正确读取