python - RPi.GPIO中wait_for_edge和event_detected有什么區別?
問題描述
比如說我要監聽一個下降沿觸發的中斷請求,并且執行一段函數,究竟該怎么寫代碼,網上各種文檔都是互相抄襲國外的機翻文檔,完全無法正常閱讀,請各位高手幫忙解答一下,謝謝!!!
問題解答
回答1:The wait_for_edge() function is designed to block execution of your program until an edge is detected.
翻譯過來就是wait_for_edge會阻塞程序,直到有一個邊沿事件被觸發
The event_detected() function is designed to be used in a loop with other things, but unlike polling it is not going to miss the change in state of an input while the CPU is busy working on other things.
event_detected就是事件觸發
具體到你這里,要中斷請求,那只能是用事件方式觸發了。
那第一步是讓接口電阻上拉
GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_UP)
然后
GPIO.add_event_detect(channel, GPIO.FALLING)GPIO.add_event_callback(channel, callback_func)
相關文章:
1. docker網絡端口映射,沒有方便點的操作方法么?2. java - spring boot 如何打包成asp.net core 那種獨立應用?3. javascript - 關于apply()與call()的問題4. docker - 各位電腦上有多少個容器啊?容器一多,自己都搞混了,咋辦呢?5. java - 在用戶不登錄的情況下,用戶如何添加保存到購物車?6. datetime - Python如何獲取當前時間7. javascript - nginx反向代理靜態資源403錯誤?8. docker start -a dockername 老是卡住,什么情況?9. 安全性測試 - nodejs中如何防mySQL注入10. python - 調用api輸出頁面,會有標簽出現,請問如何清掉?
