Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. PIN_TRIGGER = 7
  4. ECHOS = [11, 13, 15]
  5. for e in ECHOS:
  6. GPIO.setup(e, GPIO.IN)
  7.  
  8. GPIO.setup(PIN_TRIGGER, GPIO.OUT)
  9.  
  10.  
  11. GPIO.output(PIN_TRIGGER, GPIO.LOW)
  12.  
  13. print ("Waiting for sensor to settle")
  14.  
  15. time.sleep(2)
  16.  
  17. print ("Calculating distance")
  18.  
  19. GPIO.output(PIN_TRIGGER, GPIO.HIGH)
  20.  
  21. time.sleep(0.00001)
  22.  
  23. GPIO.output(PIN_TRIGGER, GPIO.LOW)
  24.  
  25. while GPIO.input(e) == 0:
  26. pulse_start_time = time.time()
  27. while GPIO.input(e) == 1:
  28. pulse_end_time = time.time()
  29.  
  30. pulse_duration = pulse_end_time - pulse_start_time
  31. distance = round(pulse_duration * 17150, 2)
  32. if distance < 30:
  33. print("Object close")
  34. #print ("Distance:",distance,"cm")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement