mirror of
https://github.com/kevinveenbirkenbach/erinaco.git
synced 2024-11-23 22:41:05 +01:00
26 lines
559 B
Python
26 lines
559 B
Python
|
#!/usr/bin/python3
|
||
|
# Datei ultraschall.py
|
||
|
import time
|
||
|
import RPi.GPIO as GPIO
|
||
|
|
||
|
GPIO.setmode(GPIO.BCM)
|
||
|
trig = 5 # GPIO-Pin-Nummern
|
||
|
echo = 17
|
||
|
GPIO.setup(echo, GPIO.IN)
|
||
|
GPIO.setup(trig, GPIO.OUT)
|
||
|
|
||
|
while True:
|
||
|
GPIO.output(trig, True)
|
||
|
time.sleep(0.00001) # 10 Mikrosekunden
|
||
|
GPIO.output(trig, False)
|
||
|
|
||
|
while GPIO.input(echo) == 0:
|
||
|
pass
|
||
|
start = time.time()
|
||
|
while GPIO.input(echo) == 1:
|
||
|
pass
|
||
|
ende = time.time()
|
||
|
entfernung = ((ende - start) * 34300) / 2
|
||
|
print("Entfernung:", entfernung, "cm")
|
||
|
time.sleep(0.5)
|