-
Notifications
You must be signed in to change notification settings - Fork 0
/
sound_v3.py
74 lines (64 loc) · 1.65 KB
/
sound_v3.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
72
73
74
import RPi.GPIO as GPIO
import time
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN)
GPIO.setup(14, GPIO.IN)
GPIO.setup(15, GPIO.IN)
GPIO.setup(18, GPIO.IN)
def detect(a):
while True:
sum = 0
signal = []
for i in a:
signal.append(GPIO.input(i))
for i in signal:
sum += i
if sum == 1:
for i in range(len(signal)):
if signal[i] == 1:
return a[i]
try:
while True:
start_time = 0
a = [4, 14, 15, 18]
b = []
time_diff = []
sensor1 = detect(a)
b.append(sensor1)
for i in range(len(a)):
if a[i] == sensor1:
a.pop(i)
break
start_time = time.time()
sensor2 = detect(a)
b.append(sensor2)
for i in range(len(a)):
if a[i] == sensor2:
a.pop(i)
break
end_time = time.time()
time_diff.append(end_time - start_time)
start_time = end_time
sensor3 = detect(a)
b.append(sensor3)
for i in range(len(a)):
if a[i] == sensor3:
a.pop(i)
break
end_time = time.time()
time_diff.append(end_time - start_time)
start_time = end_time
sensor4 = detect(a)
b.append(sensor4)
for i in range(len(a)):
if a[i] == sensor4:
a.pop(i)
break
end_time = time.time()
time_diff.append(end_time - start_time)
print(b)
print(time_diff)
time.sleep(0.3)
except KeyboardInterrupt:
GPIO.cleanup()