title: how to count the time from LOW to HIGH pin level in python
body: <p>i have this code right here:</p>
  
  <pre><code>import datetime
  import time
  import math
  import RPi.GPIO as GPIO
  GPIO.setmode(GPIO.BCM)
  
  GPIO.setup(20,GPIO.IN)
  input = GPIO.input(20)
  
  #initialise a previous input variable to 0 (assume button not pressed last)
  
  prev_input = 0
  D = 0.66       #wheel diameter
  while True:
  #take a reading
  input = GPIO.input(20)
  
  #if last was low and this one's high, do:
  
  if ((not prev_input) and input):
  
    end_time = datetime.datetime.now()             # timestamp
    s = time.mktime(end_time.timetuple())  
    #delta_time = s - c                            #difference of times ???
  
    #instant_speed = ((math.pi * D) / delta_time)  #moment speed
  
    print 'magnet touched', s
  
  #if LOW, do:
  
  if ( input == 0 ):
  
   start_time = datetime.datetime.now()    #timestamp
   c = time.mktime(start_time.timetuple()) 
  
   print 'not touched', c
  
  #update previous input
  prev_input = input
  #slight pause to debounce
  #time.sleep(0.05)
  </code></pre>
  
  <p>I want to count the time passed since the LOW level of the PIN20 changed to HIGH and then use the difference of time in my further speed countings.
  This is a code for a reed switch, what i am planning to do is to make it as a speed counter.</p>
  
  <p>Could anyone give me a hint of how to calculate the time? Thank you.</p>