-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
38 lines (32 loc) · 877 Bytes
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#def sensor()
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
global pinoTrigger = 17
global pinoEcho = 18
global GPIO.setup(pinoTrigger, GPIO.OUT)
global GPIO.setup(pinoEcho, GPIO.IN)
def sensor():
try:
while True:
GPIO.output(pinoTrigger,False)
time.sleep(1)
GPIO.output(pinoTrigger,True)
time.sleep(0.0001)
GPIO.output(pinoTrigger,False)
tempoI = time.time()
while GPIO.input(pinoecho)==0:
tempoI = time.time()
while GPIO.input(pinoecho)==1:
tempoF = time.time()
tempocorrido = tempoF - tempoI
distancia = (tempocorrido)/2 * 34326
print("Distancia: ",distancia)
return(distancia)
time.sleep(0.5)
while True:
if sensor() < 80:
GPIO.output(buzina,True)
time.sleep(30)
GPIO.output(buzina,False)