Skip to content

Instantly share code, notes, and snippets.

Created August 8, 2017 21:23
What would you like to do?
How to add a delay between the button press, and PiCamera taking a photo, using sleep().
from time import sleep
import RPi.GPIO as GPIO
import picamera
#... etc.
# Refer related gists, for how to setup the camera ...etc.
#Wait for someone to push the button
while True:
#Check to see if button is pushed
is_pressed = GPIO.wait_for_edge(21, GPIO.FALLING, timeout=100) #Check if Pin 21 is pressed
#Stay inside loop until button is pressed
if is_pressed is None:
continue # Go back to check if the button is pressed again.
#Button has been pressed!
print("Button pressed!")
camera.start_preview(resolution=(screen_w, screen_h)) #Start camera preview
#Wait for 2 seconds.
#Save photo
#restart loop
is_pressed = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment