CARIA.1.0.0
Restruct all repositories Add : - Files UserWebSite - IA openCV Tuto - Alphabot docs for first maquette
This commit is contained in:
30
AlphaBot-CARIA/Pi-python/Ultrasonic_Ranging.py
Normal file
30
AlphaBot-CARIA/Pi-python/Ultrasonic_Ranging.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
|
||||
TRIG = 17
|
||||
ECHO = 5
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setup(TRIG,GPIO.OUT,initial=GPIO.LOW)
|
||||
GPIO.setup(ECHO,GPIO.IN)
|
||||
|
||||
def dist():
|
||||
GPIO.output(TRIG,GPIO.HIGH)
|
||||
time.sleep(0.000015)
|
||||
GPIO.output(TRIG,GPIO.LOW)
|
||||
while not GPIO.input(ECHO):
|
||||
pass
|
||||
t1 = time.time()
|
||||
while GPIO.input(ECHO):
|
||||
pass
|
||||
t2 = time.time()
|
||||
return (t2-t1)*34000/2
|
||||
|
||||
try:
|
||||
while True:
|
||||
print("HELLO")
|
||||
print("Distance:%0.2f cm" % dist())
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
GPIO.cleanup()
|
||||
Reference in New Issue
Block a user