import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
trig=7
echo=11
t=time.time()
GPIO.setup(7,GPIO.OUT)
GPIO.setup(11,GPIO.IN)
While (t+3)>time.time():
start=0
end=0
GPIO.output(trig,True)
time.sleep(0.000001)
GPIO.output(trig,False)
while GPIO.input(echo)==False:
start=time.time()
while GPIO.input(echo)==True:
end=time.time()
sig_time = end-start
dist = sig_time * 17000
print("dist: ",dist)
time.sleep(0.5)
GPIO.cleanup()
Ultrasonic sensor. It works when while t+3 code is not included.but when it is it dosnt why. it just run but no output. After if i run it again it give runtime warning gpio already in use why? Plz give me suitable code to run it for 3s giving all distances
While
is not valid PythonWhile
with a captial W is not valid Python. It must bewhile
.