python - RPi.GPIO中wait_for_edge和event_detected有什么區(qū)別?
問題描述
比如說我要監(jiān)聽一個(gè)下降沿觸發(fā)的中斷請求,并且執(zhí)行一段函數(shù),究竟該怎么寫代碼,網(wǎng)上各種文檔都是互相抄襲國外的機(jī)翻文檔,完全無法正常閱讀,請各位高手幫忙解答一下,謝謝!!!
問題解答
回答1:The wait_for_edge() function is designed to block execution of your program until an edge is detected.
翻譯過來就是wait_for_edge會(huì)阻塞程序,直到有一個(gè)邊沿事件被觸發(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. 求救一下,用新版的phpstudy,數(shù)據(jù)庫過段時(shí)間會(huì)消失是什么情況?2. php工具箱配置第二個(gè)vhost主機(jī)時(shí)不生效,報(bào)錯(cuò)You don’t have permission3. php - mysql 模糊搜索問題4. html - 爬蟲時(shí)出現(xiàn)“DNS lookup failed”,打開網(wǎng)頁卻沒問題,這是什么情況?5. javascript - 在 vue里面用import引入js文件,結(jié)果為undefined6. [python2]local variable referenced before assignment問題7. javascript - js setTimeout在雙重for循環(huán)中如何使用?8. php - 微信開發(fā)驗(yàn)證服務(wù)器有效性9. javascript - 我的站點(diǎn)貌似被別人克隆了, google 搜索特定文章,除了域名不一樣,其他的都一樣,如何解決?10. javascript - 求幫助 , ATOM不顯示界面!!!!
