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. 老师百度网盘分享一下WampServer的包啊,我们下载几kb要下载一天的.2. php代码运行报错3. 我 想好好学精通一门技术,大家用的走过的路,帮我指点指点呗 让我少走了弯路和坑的苦 ,自学,自己摸4. javascript - 有没有什么办法过滤掉数据库中的乱码?5. composer安装一直提示需要gmp扩展6. mysql - 数据库字段命名问题,新人,求解7. javascript - onclick事件点击不起作用8. phpstudy 发现多个后门木马,有人遇到过吗?9. php工具中的mysql还是5.1以下的,请问如何才能升级到5.1以上?10. mysql根据输入的字段数据获取到ID怎么解决??

网公网安备