import RPi.GPIO as GPIO from time import sleep from datetime import datetime from subprocess import call def start_stop_bleep (): for x in range (0,3): GPIO.output(sounder, GPIO.HIGH) sleep (0.25) GPIO.output(sounder, GPIO.LOW) sleep (0.25) sounder = 2 # GPIO number pushbutton = 3 # GPIO number dir = "/home/pi/" GPIO.setmode(GPIO.BCM) GPIO.setup(sounder, GPIO.OUT) GPIO.setup(pushbutton, GPIO.IN, pull_up_down = GPIO.PUD_UP) start_stop_bleep () # indicate powered up while (True): if (GPIO.input(pushbutton) == 0): # Shutter release GPIO.output(sounder, GPIO.HIGH) # short bleep sleep (0.5) GPIO.output(sounder, GPIO.LOW) filename= "img_" + datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + ".jpg" cmd = "raspistill -o " + dir + filename call (cmd, shell=True) GPIO.output(sounder, GPIO.HIGH) # long bleep sleep (1) GPIO.output(sounder, GPIO.LOW) if (GPIO.input(pushbutton) == 0): # shutdown initiated GPIO.output(sounder, GPIO.LOW) sleep (0.5) start_stop_bleep () # indicate shutting down call ("sudo shutdown -h now", shell=True)