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. javascript - 百度坐标,返回目标附近有哪些坐标2. javascript - 关于jsp中嵌入js代码的问题3. javascript - 有什么兼容性比较好的办法来判断浏览器窗口的类型?4. javascript - 一个JS多元运算符的问题5. javascript - html5多个label中其中一个触发change,如何判断是哪一个出发了change6. javascript - 判断用户网络环境7. clone - git sourceTree克隆仓库时,都不停弹出Password Required弹窗,即时输入正确的git账号密码还是弹出8. python - 怎么通过vpn连内网ftp?9. angular.js - angurlarJS的安卓的微信端中用加载ngCookies会出错的问题10. python 正则表达式提取

网公网安备