# -*- coding: utf-8 -*- from RPi import GPIO from datetime import datetime import os, time GPIOPin = 17 def button_callback(gpio_number): print("Button pressed!") datetime_string = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") filename = "/home/pi/img_%s.jpg" % datetime_string os.system("raspistill -o %s" % filename) GPIO.setmode(GPIO.BCM) GPIO.setup(GPIOPin, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) GPIO.add_event_detect(GPIOPin, GPIO.RISING, callback=button_callback) try: while True: time.sleep(0.01) except: GPIO.cleanup()