python - RPi.GPIO中wait_for_edge和event_detected有什么區別?
問題描述
比如說我要監聽一個下降沿觸發的中斷請求,并且執行一段函數,究竟該怎么寫代碼,網上各種文檔都是互相抄襲國外的機翻文檔,完全無法正常閱讀,請各位高手幫忙解答一下,謝謝!!!
問題解答
回答1:The wait_for_edge() function is designed to block execution of your program until an edge is detected.
翻譯過來就是wait_for_edge會阻塞程序,直到有一個邊沿事件被觸發
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就是事件觸發
具體到你這里,要中斷請求,那只能是用事件方式觸發了。
那第一步是讓接口電阻上拉
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. MySQL 使用 group by 之后然后 IFNULL(COUNT(*),0) 為什么還是會獲得 null2. wordpress里,這樣的目錄列表是屬于小工具還是啥?3. 一直報這個錯誤4. 常量在外面不加引號會報錯。5. python如何設置一個隨著系統時間變化的動態變量?6. mysql - 大部分數據沒有行溢出的text字段是否需要拆表7. mysql federated引擎無法開啟8. sublime text3安裝package control失敗9. 我的怎么不顯示啊,話說有沒有QQ群什么的10. mysql 為什么主鍵 id 和 pid 都市索引, id > 10 走索引 time > 10 不走索引?
