python - RPi.GPIO中wait_for_edge和event_detected有什么區(qū)別?
問題描述
比如說我要監(jiān)聽一個下降沿觸發(fā)的中斷請求,并且執(zhí)行一段函數(shù),究竟該怎么寫代碼,網(wǎng)上各種文檔都是互相抄襲國外的機翻文檔,完全無法正常閱讀,請各位高手幫忙解答一下,謝謝!!!
問題解答
回答1:The wait_for_edge() function is designed to block execution of your program until an edge is detected.
翻譯過來就是wait_for_edge會阻塞程序,直到有一個邊沿事件被觸發(fā)
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就是事件觸發(fā)
具體到你這里,要中斷請求,那只能是用事件方式觸發(fā)了。
那第一步是讓接口電阻上拉
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. ruby - gitlab托管,git clone 失敗?2. javascript - node.js promise沒用3. android 如何實現(xiàn)如圖中的鍵盤上的公式及edittext的內容展示呢4. javascript - js 寫一個正則 提取文本中的數(shù)據(jù)5. 算法 - python 給定一個正整數(shù)a和一個包含任意個正整數(shù)的 列表 b,求所有<=a 的加法組合6. golang - 用IDE看docker源碼時的小問題7. yii2中restful配置好后在nginx下報404錯誤8. c++ - 如何正確的使用QWebEngineView?9. java - 我在用Struts2上傳文件時,報以下錯誤怎么回事?10. 網(wǎng)站被黑,請教下大神,怎么對datebase.php內容加密。
