-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomatenfuellstand.py
71 lines (62 loc) · 1.94 KB
/
automatenfuellstand.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
def distanceMeasurement(TRIG,ECHO):
time.sleep(1)
global pulseStart
pulseStart = time.time()
pulseEnd = time.time()
pulseDuration = 0
distance = 0
GPIO.output(TRIG, True)
time.sleep(0.001)
GPIO.output(TRIG, False)
while GPIO.input(ECHO) == 0:
pulseStart = time.time()
while GPIO.input(ECHO) == 1:
pulseEnd = time.time()
pulseDuration = pulseEnd - pulseStart
distance = pulseDuration * 17150
distance = round(distance, 2)
return distance
#Configuration
GPIO_TRG_LIST = (14,8,24,4,27,18)
GPIO_ECH_LIST = (15,7,25,17,22,23)
GPIO.setup(GPIO_TRG_LIST,GPIO.OUT) #Trigger
GPIO.setup(GPIO_ECH_LIST,GPIO.IN) #Echo
#Security
GPIO.output(14, False)
GPIO.output(8, False)
GPIO.output(24, False)
GPIO.output(4, False)
GPIO.output(27, False)
GPIO.output(18, False)
time.sleep(0.5)
#main Loop
try:
while True:
for i in range(6):
if i == 0:
recoveredDistance = distanceMeasurement(14,15)
print "Distance1: ",recoveredDistance,"cm"
elif i == 1:
recoveredDistance = distanceMeasurement(8,7)
print "Distance2: ",recoveredDistance,"cm"
elif i == 2:
recoveredDistance = distanceMeasurement(24,25)
print "Distance3: ",recoveredDistance,"cm"
elif i == 3:
recoveredDistance = distanceMeasurement(4,17)
print "Distance4: ",recoveredDistance,"cm"
elif i == 4:
recoveredDistance = distanceMeasurement(27,22)
print "Distance5: ",recoveredDistance,"cm"
elif i == 5:
recoveredDistance = distanceMeasurement(18,23)
print "Distance6: ",recoveredDistance,"cm"
time.sleep(1)
except KeyboardInterrupt:
print "Measurement stopped by user"
GPIO.cleanup()