User Guide

196
Add a call to capture() above the os.system() call. For example:
camera.capture("Ring %s.jpg" % time.strftime("%Y%m%d-
%H%M%S"))
The full Python script should look like this:
import RPi.GPIO
import os
import picamera
import time
RPi.GPIO.setmode(RPi.GPIO.BCM)
RPi.GPIO.setup(2, RPi.GPIO.IN,
pull_up_down=RPi.GPIO.PUD_UP)
camera = picamera.PiCamera()
def Ring():
camera.capture("Ring %s.jpg" % time.strftime("%Y%m%d-
%H%M%S"))
os.system("mpg321 ring.mp3")
while RPi.GPIO.input(2) == RPi.GPIO.LOW:
pass
while True:
if RPi.GPIO.input(2) == RPi.GPIO.LOW:
Ring()
The string passed into strftime() determines the format of the
date and time string. For more information about the time
module, see http://docs.python.org/3/library/time.html