-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathpushbutton_image_capture.py
More file actions
31 lines (28 loc) · 1002 Bytes
/
pushbutton_image_capture.py
File metadata and controls
31 lines (28 loc) · 1002 Bytes
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
# Import libraries
from gpiozero import Button
from picamera import PiCamera
from time import sleep
# Create a button object and initialize it with GPIO pin 2
# --> Change GPIO pin as needed
button = Button(2)
# Create a camera object
camera = PiCamera()
while True:
if button.is_pressed:
print("Pressed")
# Start the camera preview, make slightly transparent to see any python output
# Note: preview only shows if you have a monitor connected directly to the Pi
camera.start_preview(alpha=200)
# Pi Foundation recommends waiting 2s for light adjustment
sleep(5)
# Optional image rotation for camera
# --> Change or comment out as needed
camera.rotation = 180
#Input image file path here
# --> Change image path as needed
camera.capture('/home/pi/Documents/image.jpg')
# Stop camera preview (important step!)
camera.stop_preview()
else:
print("waiting")
sleep(1)