Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- PIN_TRIGGER = 7
- ECHOS = [11, 13, 15]
- for e in ECHOS:
- GPIO.setup(e, GPIO.IN)
- GPIO.setup(PIN_TRIGGER, GPIO.OUT)
- GPIO.output(PIN_TRIGGER, GPIO.LOW)
- print ("Waiting for sensor to settle")
- time.sleep(2)
- print ("Calculating distance")
- GPIO.output(PIN_TRIGGER, GPIO.HIGH)
- time.sleep(0.00001)
- GPIO.output(PIN_TRIGGER, GPIO.LOW)
- while GPIO.input(e) == 0:
- pulse_start_time = time.time()
- while GPIO.input(e) == 1:
- pulse_end_time = time.time()
- pulse_duration = pulse_end_time - pulse_start_time
- distance = round(pulse_duration * 17150, 2)
- if distance < 30:
- print("Object close")
- #print ("Distance:",distance,"cm")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement