Home  >  Q&A  >  body text

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

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

PHP中文网PHP中文网2741 days ago533

reply all(1)I'll reply

  • 阿神

    阿神2017-04-18 10:36:14

    The wait_for_edge() function is designed to block execution of your program until an edge is detected.

    The translation is wait_for_edge will block the program until an edge event is triggered

    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 is the event trigger

    Specifically for you, if you want to interrupt the request, it can only be triggered by an event.

    The first step is to pull up the interface resistor

    GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    Then

    GPIO.add_event_detect(channel, GPIO.FALLING)
    GPIO.add_event_callback(channel, callback_func)

    reply
    0
  • Cancelreply