python - RPi.GPIO中wait_for_edge和event_detected有什么區(qū)別?
問題描述
比如說我要監(jiān)聽一個(gè)下降沿觸發(fā)的中斷請(qǐng)求,并且執(zhí)行一段函數(shù),究竟該怎么寫代碼,網(wǎng)上各種文檔都是互相抄襲國外的機(jī)翻文檔,完全無法正常閱讀,請(qǐng)各位高手幫忙解答一下,謝謝!!!
問題解答
回答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ā)
具體到你這里,要中斷請(qǐng)求,那只能是用事件方式觸發(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. debian - docker依賴的aufs-tools源碼哪里可以找到啊?2. dockerfile - 我用docker build的時(shí)候出現(xiàn)下邊問題 麻煩幫我看一下3. docker網(wǎng)絡(luò)端口映射,沒有方便點(diǎn)的操作方法么?4. docker-compose 為何找不到配置文件?5. macos - mac下docker如何設(shè)置代理6. docker start -a dockername 老是卡住,什么情況?7. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個(gè)是怎么回事????8. 如何解決Centos下Docker服務(wù)啟動(dòng)無響應(yīng),且輸入docker命令無響應(yīng)?9. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問題。10. docker gitlab 如何git clone?

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