Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import os
- import time
- from time import sleep
- import picamera
- import RPi.GPIO as GPIO
- ########################
- ### Variables Config ###
- ########################
- button1_pin = 11
- led1_pin = 15 #red LED
- led2_pin = 13 # yellow LED
- led3_pin = 7 # green LED
- total_pics = 4 # number of pics to be taken
- capture_delay = 2 # delay between pics
- prep_delay = 4 # number of seconds at step 1 as users prep to have photo taken
- file_path = '/home/pi/photobooth/' #where do you want to save the photos
- GPIO.setmode(GPIO.BOARD)
- GPIO.setup(button1_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # falling edge detection on button 1
- GPIO.setup(led1_pin,GPIO.OUT) # LED 1 (red)
- GPIO.setup(led2_pin,GPIO.OUT) # LED 2 (yellow)
- GPIO.setup(led3_pin,GPIO.OUT) # LED 3 (green)
- GPIO.output(led1_pin,False);
- GPIO.output(led2_pin,False);
- GPIO.output(led3_pin,False);
- def start_photobooth():
- print "Get Ready"
- camera = picamera.PiCamera()
- camera.resolution = (640, 480) #use a smaller size to process faster
- camera.brightness = 55
- camera.vflip = False
- camera.hflip = True
- camera.start_preview()
- i=1
- print "Taking pics"
- now = time.strftime("%Y%m%d%H%M%S") #get the current date and time for the start of the filename
- try: #take the photos
- for i, filename in enumerate(camera.capture_continuous(file_path + now + '-' + '{counter:02d}.jpg')):
- GPIO.output(led1_pin,True)
- sleep(1)
- GPIO.output(led1_pin,False)
- GPIO.output(led2_pin,True)
- sleep(1)
- GPIO.output(led2_pin,False)
- GPIO.output(led3_pin,True) # turn on LED 3
- print(filename)
- sleep(1) #pause the LED on for just a bit
- GPIO.output(led3_pin,False) # turn off LED 3
- sleep(capture_delay) # pause in-between shots
- if i == total_pics-1:
- break
- finally:
- camera.stop_preview()
- camera.close()
- # wait for the big button to be pressed
- while True:
- GPIO.wait_for_edge(button1_pin, GPIO.FALLING)
- time.sleep(0.2) #debounce
- start_photobooth()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement