How to add a delay between the button press, and PiCamera taking a photo, using sleep().
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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