python - RPi.GPIO中wait_for_edge和event_detected有什么区别?

查看:237
本文介绍了python - RPi.GPIO中wait_for_edge和event_detected有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

比如说我要监听一个下降沿触发的中断请求,并且执行一段函数,究竟该怎么写代码,网上各种文档都是互相抄袭国外的机翻文档,完全无法正常阅读,请各位高手帮忙解答一下,谢谢!!!

解决方案

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)

这篇关于python - RPi.GPIO中wait_for_edge和event_detected有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆