I read some GPIO interrupt documentation on the web like this and there is one question left for me: Needs using GPIO.add_event_detect(<PIN>, <GPIO.EDGE>, callback=<some callback function>, bouncetime=<int>)
in a python script to have a while true
loop in the same script to run this script "endless" in order to handle the callback routine?
Let's make it more clear. My script should look like this:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(6, GPIO.OUT)
def my_interrupt_routine(channel):
#do something here
GPIO.add_event_detect(6, GPIO.FALLING, callback=my_interrupt_routine, bouncetime=200)
try:
while True:
pass
except KeyboardInterrupt:
#do something here
finally:
GPIO.cleanup()
So with this script - is it necessary to have the while true:
loop to let the interrupt handler wait for the falling edg on Pin6 or can I just activate the handler and end the program?
I'm asking this because I read many articles about the advantage of using interrupt handler versus polling the GPIO-Pin. And this while true:
loop looks pretty much the same to me like polling around on Pins.
I used to develop in Java. There you define the interrupt handler/listener and somewhere at the other end of the world you can then handle the event. I assume this won't work in Python, right?