I've got a photo booth program I'm working on that takes the photo of the user and displays it on the screen for 5-10 seconds. At the end of that 5-10 seconds, I'd like the booth to reset unless a particular GPIO button has been pressed.

I was able to find an analogous code snippet to what I'd like to do, but I can't seem to make it take GPIO.input() or GPIO event detection into account. Trying GPIO.wait_for_event, just causes the process to hang while it waits for input. It's important that the default operation is to just reset the photobooth for the next person (without intervention).

#!/usr/bin/env python
import time
from threading import Thread

answer = None
def check():
    if answer == 'y':
        print "\nSounds good, I'll send it to the queue!"
    print "\nMoving on..."

answer = raw_input("You have 5 seconds. Print? [y/n]: ") 

1 Answer 1


There will be hundreds of ways of achieving what you want.

Here is my take.

#!/usr/bin/env python

import time

import pigpio # http://abyz.me.uk/rpi/pigpio/python.html


pi = pigpio.pi()
if not pi.connected:

stop = time.time() + 60

while time.time() < stop:

   # Put code here

   print("press button to print photo")

   if pi.wait_for_edge(BUTTON, pigpio.FALLING_EDGE, 5): # 5 second t/o
      # Button pressed
      print("printing photo")
      # No button press
      print("dumping photo")

   # Put code here



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.