Skip to content

Instantly share code, notes, and snippets.

Created March 2, 2017 02:19
Show Gist options
  • Save anonymous/fdf5c09391dee8ba5102f64a81bb8bbf to your computer and use it in GitHub Desktop.
Save anonymous/fdf5c09391dee8ba5102f64a81bb8bbf to your computer and use it in GitHub Desktop.
from gpiozero import DistanceSensor
from time import sleep
from gpiozero import LED
from gpiozero import pause
Requirement = input('Input required distance in [cm]: ')
led = LED(5)
sensor = DistanceSensor(echo=18, trigger=17)
while True:
print('Distance: ', sensor.distance * 100)
DistanceRead = sensor.distance * 100
if DistanceRead == Requirement:
led.on()
else led.off()
pause()
sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment