Skip to content

Instantly share code, notes, and snippets.

@jibbius
Created August 8, 2017 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jibbius/17d3d303dd1d888e76c6ae881a4b462a to your computer and use it in GitHub Desktop.
Save jibbius/17d3d303dd1d888e76c6ae881a4b462a to your computer and use it in GitHub Desktop.
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.
sleep(2)
#Save photo
camera.capture('my_file.jpg')
#restart loop
camera.stop_preview()
is_pressed = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment