Advertisement
Guest User

Vehicle Counting with IR Sensor

a guest
Nov 18th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import time
  3. import pifacedigitalio as pio
  4.  
  5. def piotrigger():
  6.     print '... Started on %s.' % time.strftime('%c')
  7.     count = 0
  8.     trucks = 0
  9.     fname = time.strftime('trucks_%d%m%Y.log')
  10.  
  11.     pio.init()
  12.     while True:
  13.         if pio.digital_read(0) == 1:
  14.             if count == 0:
  15.                 pio.digital_write(2, 1)
  16.  
  17.             count += 1
  18.             if count == 1000:
  19.                 trucks += 1
  20.                 pio.digital_write(3, 1)
  21.                 print 'Number of trucks:', trucks
  22.                 with open(fname, 'w') as truckfile:
  23.                     truckfile.write('%d\n' % trucks)
  24.  
  25.         elif count > 0:
  26.             pio.digital_write(2, 0)
  27.             pio.digital_write(3, 0)
  28.             count = 0
  29.  
  30.         time.sleep(0.01)
  31.  
  32. piotrigger()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement