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. docker - 各位电脑上有多少个容器啊?容器一多,自己都搞混了,咋办呢?2. docker api 开发的端口怎么获取?3. android - 哪位大神知道java后台的api接口的对象传到前端后输入日期报错,是什么情况?求大神指点4. docker - 如何修改运行中容器的配置5. docker容器呢SSH为什么连不通呢?6. html - 爬虫时出现“DNS lookup failed”,打开网页却没问题,这是什么情况?7. docker网络端口映射,没有方便点的操作方法么?8. docker绑定了nginx端口 外部访问不到9. 关docker hub上有些镜像的tag被标记““This image has vulnerabilities””10. mac连接阿里云docker集群,已经卡了2天了,求问?

网公网安备