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 - react能够使用什么时间插件2. node.js - 我是一个做前端的,求教如何学习vue,node等js引擎?3. docker api 开发的端口怎么获取?4. 如何解决Centos下Docker服务启动无响应,且输入docker命令无响应?5. 前端 - 类到底该如何去命名 .newsList 这种的命名难道真的不是过度语义化吗?~6. java - 为什么第一个线程已经释放了锁,第二个线程却不行?7. 如何解决docker宿主机无法访问容器中的服务?8. PHP中的$this代表当前的类还是方法?9. sublime-text - sublime text 3中编译python(sublimeREPL),如何仅运行单行/选定部分10. 老师,flex-shrink: 1; 按视频操作,不会自动缩放

网公网安备