Skip to content

Instantly share code, notes, and snippets.

@atifahsuad
Created November 1, 2018 04:25
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 atifahsuad/e5fd6f1f0fed2065350e5493f4fbef49 to your computer and use it in GitHub Desktop.
Save atifahsuad/e5fd6f1f0fed2065350e5493f4fbef49 to your computer and use it in GitHub Desktop.
This example code is for Raspberry Pi Selfie Tutorial.
import RPi.GPIO as GPIO
from picamera import PiCamera
import time
from time import sleep
camera = PiCamera()
Button = 20
Buzzer = 26
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(Button, GPIO.IN, GPIO.PUD_UP)
GPIO.setup(Buzzer,GPIO.OUT)
def beep(times, sec):
for x in range(times):
GPIO.output(Buzzer,GPIO.HIGH)
sleep(sec)
GPIO.output(Buzzer,GPIO.LOW)
sleep(sec)
try:
while True:
if GPIO.input(Button) == 0:
beep(2, 0.07)
filename = (time.strftime("%y%b%d_%H:%M"))
camera.rotation = 180
camera.start_preview(fullscreen=False, window = (600, 10, 640, 480))
sleep(3)
beep(1, 0.5)
variable = "/home/pi/Desktop/" + filename + ".jpg"
camera.capture(variable)
#camera.capture("/home/pi/Desktop/{0}".format(Filename))
camera.stop_preview()
else :
GPIO.output(Buzzer,GPIO.LOW)
except KeyboardInterrupt:
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment