testUS.py hinzugefügt
This commit is contained in:
21
testUS.py
Normal file
21
testUS.py
Normal file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from gpiozero import DistanceSensor
|
||||
from time import sleep
|
||||
|
||||
trigPin = 23
|
||||
echoPin = 24
|
||||
sensor = DistanceSensor(echo=echoPin, trigger=trigPin ,max_distance=3)
|
||||
|
||||
def loop():
|
||||
while True:
|
||||
print('Der abstand ist : ', sensor.distance * 100,'cm')
|
||||
sleep(0.05)
|
||||
|
||||
if __name__ == '__main__': # Program entrance
|
||||
print ('Program is starting...')
|
||||
try:
|
||||
loop()
|
||||
except KeyboardInterrupt: # Press ctrl-c to end the program.
|
||||
sensor.close()
|
||||
print("Ending program")
|
||||
Reference in New Issue
Block a user