Created
October 18, 2019 15:41
-
-
Save djbeadle/e4ac7f46b0f22ce0fd23b9e397ea9048 to your computer and use it in GitHub Desktop.
Simple RasPi Camera & Light
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 gpiozero import LED | |
import time | |
from picamera import PiCamera | |
import os | |
#Load the camera | |
camera = PiCamera() | |
camera.resolution = (1024, 768) | |
camera.start_preview() | |
time.sleep(2) | |
#Create a new folder | |
path = os.getcwd() | |
path += "/output" | |
filenum = 1 | |
filename=f"{path}/{filenum}" | |
while(True): | |
try: | |
os.mkdir(filename) | |
except OSError as e: | |
filenum += 1 | |
filename = f"{path}/{filenum}" | |
else: | |
break | |
#Take a photo in the directory test | |
camera.capture(f"{filename}/img.jpg") | |
# This piece of code uses a different, less user-friendly | |
# library for controlling the GPIO pins to ensure that | |
# the LED remains off when the program is finished. | |
PIN_TO_TURN_OFF = 12 | |
import RPi.GPIO as GPIO | |
GPIO.setmode(GPIO.BOARD) | |
GPIO.setwarnings(False) | |
GPIO.setup(PIN_TO_TURN_OFF, GPIO.OUT) | |
GPIO.output(PIN_TO_TURN_OFF, False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment