raspberry pi - Python whats the most efficient way to wait for input -
i have python program want run in background (on raspberry pi) waits gpio input performs action , continues waiting input until process killed.
what efficient way achieve this. understanding using while true not efficient. ideally use interrupts - , use gpio.wait_for_edge - need in loop or way of continuing operation upon completion of handler.
thanks
according this: http://raspi.tv/2013/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio gpio.wait_for_edge(23, gpio.falling) wait transition on pin 23 using interrupts instead of polling. it'll continue when triggered. can enclose in try: / except keyboardinterrupt catch ctrl-c.
if want continue processing should register call function interrupt. see: http://sourceforge.net/p/raspberry-gpio-python/wiki/inputs/
def callback(channel): here gpio.add_event_detect(channel, gpio.rising, callback=my_callback) continue program here, in sort of state machine
Comments
Post a Comment