1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Pisrf performance fix (#309)

* performance fix

* performance fix
This commit is contained in:
bartbutenaers 2017-05-08 09:57:29 +02:00 committed by Dave Conway-Jones
parent 0fb8a1a2a0
commit 2700a2c300

View File

@ -33,6 +33,12 @@ def Measure():
Main() Main()
while GPIO.input(ECHO)==1: while GPIO.input(ECHO)==1:
stop = time.time() stop = time.time()
Dif = time.time() - realstart
if Dif > 5:
print("Ultrasonic Sensor Timed out, Restarting.")
time.sleep(0.4)
Main()
elapsed = stop-start elapsed = stop-start
distance = (elapsed * 36000)/2 distance = (elapsed * 36000)/2
@ -65,7 +71,7 @@ if len(sys.argv) > 1:
distance = int( Measure() + 0.5 ) distance = int( Measure() + 0.5 )
if distance != OLD: if distance != OLD:
print(distance) print(distance)
OLD = distance OLD = distance
time.sleep(0.5) time.sleep(0.5)
except: # try to clean up on exit except: # try to clean up on exit
print("0.0"); print("0.0");