2

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():
    time.sleep(5)
    if answer == 'y':
        print "\nSounds good, I'll send it to the queue!"
        time.sleep(1)
    print "\nMoving on..."

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

1 Answer 1

2

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

BUTTON=23

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

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")
   else:
      # No button press
      print("dumping photo")

   # Put code here

   time.sleep(1)

pi.stop()

Your Answer

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

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