new_contents: #!/usr/bin/env python
  
  ##############################################################################
  #
  # Written by Dominic Bolding for The Raspberry Pi - 2017
  #
  # Website: myhydropi.com
  # Contact: admin@myhydropi.com
  #
  # This program will recognise a button push on GPIO pin 27 and take a photo.
  # If the button is held down then it will continue to take photo's every second
  # until the button is relased. Images are store in order to the specified
  # folder, if the folder does not exist then the program will create one.
  #
  # GPIO pins use the Broadcom pin numbering scheme
  #
  ##############################################################################
  
  import os.path
  from time import sleep
  import RPi.GPIO as GPIO
  from picamera import PiCamera
  
  
  # Configures pin numbering to Broadcom reference
  GPIO.setmode(GPIO.BCM)
  
  # Set GPIO pin to input and activate pull_down resistor
  GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
  
  camera = PiCamera()
  image_no = 1
  
  # Set where you want the image saved
  image_folder = ('/home/pi/myprojects/Cam_Images')
  
  
  # Check that the directory to save the images exists, if not create one
  if not os.path.exists(image_folder):
      print ("Making Directory")  # Not required testing only
      os.makedirs(image_folder)
  
  print ("Ready")  # Not required testing only
  
  try:
      while True:
          if GPIO.input(27):  # Check for PIR sensor trigger
              print ("Button Pushed")  # Not required testing only
              # Check file name so that you don't overwrite an existing image
              while os.path.isfile('/home/pi/myprojects/Cam_Images/image%s.jpg' %image_no):
                  image_no += 1
              # Take and save picture
              camera.start_preview()  # Not required testing only
              sleep(1)  # Time between shots if button is held down
              camera.capture('/home/pi/myprojects/Cam_Images/image%s.jpg' %image_no)
              camera.stop_preview()  # Not required testing only
              print ("Picture Captured")  # Not required testing only
  except KeyboardInterrupt:
      print ("Shutting Down")  # Not required testing only
      GPIO.cleanup()
  
subject: Create Button_Camera.py