python 3.x - Two sensors, Is it possible to pause a sensor for a short time? -
i have code saving data online. have 2 ir sensors reading door, 1 6 inches other. if first sensor goes off before second, know entering room, , code sends +1 file online. when second sensor triggered first, means leaving, system should pause , nothing should happen until person moves out of both sensors. last part isnt happening. how can pause first sensor when leaving, not accidentally double count?
code:
#!/usr/bin/python3.4 ubidots import apiclient import rpi.gpio gpio import time import datetime import os import web person_count = 0 ts = time.time() st = datetime.datetime.fromtimestamp(ts).strftime('%m-%d-%y %i:%m:%s') gpio.setmode(gpio.bcm) gpio.setup(4, gpio.in) #ir sensor closest door gpio.setup(25, gpio.in) #ir sensor farthest door gpio.setup(17, gpio.out) #led indicate when data being recorded web. api = apiclient("165c54954ee6d8f7324366495cab70217c7c3c91") test_variable = api.get_variable("559c18cc76254214be90fe05") while true: # if leaves, wait 1 second. if gpio.input(4) == 0 , gpio.input(25) == 1: gpio.output(17, false) time.sleep(2) # if both sensors blocked, wait 1 second until clear elif gpio.input(4) == 1 , gpio.input(25) == 1: gpio.output(17, false) time.sleep(2) # if neither sensor blocked, wait 0.1 seconds. elif gpio.input(4) == 0 , gpio.input(25) == 0: gpio.output(17, false) time.sleep(0.1) # if first sensor (4) blocked, send person count ubidots prog$ elif gpio.input(4) == 1 , gpio.input(25) == 0: gpio.output(17, true) person_count += 1 test_value = person_count test_variable.save_value({'value':test_value}) time.sleep(1.5)
Comments
Post a Comment