Forked from anonymous/gist:fdf5c09391dee8ba5102f64a81bb8bbf
Last active
March 2, 2017 02:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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