Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import time
- import pifacedigitalio as pio
- def piotrigger():
- print '... Started on %s.' % time.strftime('%c')
- count = 0
- trucks = 0
- fname = time.strftime('trucks_%d%m%Y.log')
- pio.init()
- while True:
- if pio.digital_read(0) == 1:
- if count == 0:
- pio.digital_write(2, 1)
- count += 1
- if count == 1000:
- trucks += 1
- pio.digital_write(3, 1)
- print 'Number of trucks:', trucks
- with open(fname, 'w') as truckfile:
- truckfile.write('%d\n' % trucks)
- elif count > 0:
- pio.digital_write(2, 0)
- pio.digital_write(3, 0)
- count = 0
- time.sleep(0.01)
- piotrigger()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement