Created
November 1, 2018 04:25
-
-
Save atifahsuad/e5fd6f1f0fed2065350e5493f4fbef49 to your computer and use it in GitHub Desktop.
This example code is for Raspberry Pi Selfie Tutorial.
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
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