Skip to content

Instantly share code, notes, and snippets.

@CodeNextAdmin
Forked from CodeNextPaco/distance-led.py
Created October 18, 2021 22:06
Show Gist options
  • Save CodeNextAdmin/5ad4f2d35a150cb2dc8dc9a58ccb5902 to your computer and use it in GitHub Desktop.
Save CodeNextAdmin/5ad4f2d35a150cb2dc8dc9a58ccb5902 to your computer and use it in GitHub Desktop.
GPIO Zero distance LED blink
from gpiozero import LED, DistanceSensor
from time import sleep
# DisanceSensor(echo, trigger)
sensor = DistanceSensor(26, 20)
led = LED(14)
blink_rate = 0
def blink(d):
if d < 1.0:
led.on()
sleep(d)
led.off()
sleep(d)
else:
led.off()
while True:
print(sensor.distance)
blink(sensor.distance)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment