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會阻塞程序,直到有一個(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. docker gitlab 如何git clone?2. docker鏡像push報(bào)錯(cuò)3. 關(guān)于docker下的nginx壓力測試4. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問題。5. android - 項(xiàng)目時(shí)間長了,字符串文件strings有的字符串可能是多余的,有沒有辦法快速檢測那些是沒用的?6. android - 七牛單次上傳單張圖片,11次6次上傳失敗7. mysql - 用PHPEXCEL將excel文件導(dǎo)入數(shù)據(jù)庫數(shù)據(jù)5000+條,本地?cái)?shù)據(jù)庫正常,線上只導(dǎo)入15條,沒有報(bào)錯(cuò),哪里的問題?8. javascript - 怎么看網(wǎng)站用了什么技術(shù)框架?9. docker不顯示端口映射呢?10. 在windows下安裝docker Toolbox 啟動Docker Quickstart Terminal 失敗!
