Skip to content

Instantly share code, notes, and snippets.

@tcarrio
Forked from anonymous/gist:fdf5c09391dee8ba5102f64a81bb8bbf
Last active March 2, 2017 02:33
Show Gist options
  • Save tcarrio/5e532f7e56b6d14fd4e0360be0a72deb to your computer and use it in GitHub Desktop.
Save tcarrio/5e532f7e56b6d14fd4e0360be0a72deb to your computer and use it in GitHub Desktop.
Displays current range sensors detected distance and turns LED on/off based on that distance compared to user input
from gpiozero import DistanceSensor
from gpiozero import LED
requirement = int(raw_input('Input required distance in [cm]: '))
led = LED(5)
sensor = DistanceSensor(echo=18, trigger=17)
while True:
distanceRead = sensor.distance * 100
print('Distance: ', distanceRead)
if distanceRead >= requirement:
led.on()
else:
led.off()
from gpiozero import DistanceSensor
from gpiozero import LED
requirement = int(input('Input required distance in [cm]: '))
led = LED(5)
sensor = DistanceSensor(echo=18, trigger=17)
while True:
distanceRead = sensor.distance * 100
print('Distance: ', distanceRead)
if(distanceRead >= requirement):
led.on()
else:
led.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment