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)
相關(guān)文章:
1. javascript - QQ第三方登錄的問題2. 在mac下出現(xiàn)了兩個docker環(huán)境3. 運行python程序時出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯誤?4. 利用IPMI遠程安裝centos報錯!5. spring-mvc - spring-session-redis HttpSessionListener失效6. 測試自動化html元素選擇器元素ID或DataAttribute [關(guān)閉]7. javascript - 最近用echarts做統(tǒng)計圖時遇到兩個問題!!8. java - Spring boot 讀取 放在 jar 包外的,log4j 配置文件,系統(tǒng)有創(chuàng)建日志文件,不寫入日志信息。9. 淺談Vue使用Cascader級聯(lián)選擇器數(shù)據(jù)回顯中的坑10. IOS app應(yīng)用軟件的id號怎么查詢?比如百度貼吧的app-id=477927813

網(wǎng)公網(wǎng)安備