title: reverse event trigger in python script
body: <p>I have a throw switch which triggers the relevant output from the script below when open but does nothing when it is closed. I would like it to do the opposite i.e. it triggers the relevant output when closed but not when open but having played around with the various parameters cannot get it to do what I want. </p>
  
  <pre><code>import RPi.GPIO as GPIO
  import smtplib
  import time
  import datetime
  
  GPIO.setmode(GPIO.BCM)
  GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  
  # function for the door opening
  def door_open():
      print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
  
  #initialise a previous input variable to 0 (assume button not pressed last)
  prev_input = 0
  while True:
    #take a reading
    input = GPIO.input(21)
    #if the last reading was low and this one high, print
    if ((not prev_input) and input):
      door_open()
    #update previous input
    prev_input = input
    #slight pause to debounce
    time.sleep(0.1)
  </code></pre>