Skip to content

Instantly share code, notes, and snippets.

@djbeadle
Created October 18, 2019 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djbeadle/e4ac7f46b0f22ce0fd23b9e397ea9048 to your computer and use it in GitHub Desktop.
Save djbeadle/e4ac7f46b0f22ce0fd23b9e397ea9048 to your computer and use it in GitHub Desktop.
Simple RasPi Camera & Light
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