-
Notifications
You must be signed in to change notification settings - Fork 1
/
take_photo.py
executable file
·35 lines (27 loc) · 829 Bytes
/
take_photo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
#
# Wait for a button to be pressed on _PIN_IN. When the button is pressed,
# illuminate the LED on _PIN_OUT as well as take a photo with the picamera
#
import RPi.GPIO as GPIO
import picamera
import time
GPIO.setmode( GPIO.BCM )
_PIN_IN = 4
_PIN_OUT = 17
GPIO.setup( _PIN_IN, GPIO.IN, pull_up_down=GPIO.PUD_UP )
GPIO.setup( _PIN_OUT, GPIO.OUT )
camera = picamera.PiCamera()
camera.start_preview()
while True:
while GPIO.input( _PIN_IN ):
pass
print "Button pressed! Activating LED..."
GPIO.output( _PIN_OUT, True )
time.sleep(0.5)
print "Taking photo and Writing output to 'camera.jpg'..."
camera.capture( 'camera.jpg' )
time.sleep(0.5)
print "Deactivating LED and waiting for another button press."
GPIO.output( _PIN_OUT, False )
GPIO.cleanup()