forked from MWHS3DInnovationsClub/3dmodel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3DMODELFINAL.py
122 lines (111 loc) · 3.32 KB
/
3DMODELFINAL.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#Forked from Tony DiCola's starter code w/ Adafruit Industries
import sys
import time
import RPi.GPIO as GPIO
import os
import Adafruit_MPR121.MPR121 as MPR121
import threading
# Create MPR121 instance.
cap = MPR121.MPR121()
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
#SOUND_MAPPING
SOUND_MAPPING = {
0: 'awing.m4a',
1: 'bwing.m4a',
2: 'cwing.m4a',
3: 'dwing.m4a',
4: 'ewing.m4a',
5: 'awinggym.m4a',
6: 'bwinggym.m4a',
7: 'cwinggym.m4a',
8: 'specgym.m4a',
9: 'hwing.m4a',
10: 'swimmingpool.m4a',
11: 'rotunda.m4a',
}
#LIGHT_MAPPING
LIGHT_MAPPING = {
0: 21,
1: 17,
2: 27,
3: 5,
4: 22,
5: 13,
6: 6,
7: 26,
8: 18,
9: 23,
10: 24,
11: 25,
}
globalPin = -1
def light(pin):
gp = LIGHT_MAPPING[pin]
globalPin = pin
GPIO.setup(gp,GPIO.OUT)
print("LED on")
GPIO.output(gp,GPIO.HIGH)
def sound(pin,x=''):
gp = LIGHT_MAPPING[pin]
GPIO.setup(gp, GPIO.OUT)
os.system('omxplayer --threshold 0 -o both /home/pi/Music/'+x+ + SOUND_MAPPING[pin])
print("LED off")
GPIO.output(gp,GPIO.LOW)
def sound2(pin):
sound(pin, 'low')
def sound3(pin):
sound(pin, 'ss')
last_touched = cap.touched()
k = -1
j = -1
# Main loop to print a message every time a pin is touched.
print('Press Ctrl-C to quit.')
while True:
current_touched = cap.touched()
# Check each pin's last and current state to see if it was pressed or released.
for i in range(12):
# Each pin is represented by a bit in the touched value. A value of 1
# means the pin is being touched, and 0 means it is not being touched.
pin_bit = 1 << i
# First check if transitioned from not touched to touched.
if current_touched & pin_bit and not last_touched & pin_bit:
print('{0} touched!'.format(i))
if i != j and k == -1:
if __name__ == '__main__':
t1 = threading.Thread(target = light, args = (i,))
t2 = threading.Thread(target = sound3, args = (i,))
t2.start()
t1.start()
j = i
t1.join()
t2.join()
os.system('omxplayer --threshold 0 -o both /home/pi/Music/more.mp3')
elif i == k:
if __name__ == '__main__':
t1 = threading.Thread(target = light, args = (i,))
t2 = threading.Thread(target = sound2, args = (i,))
t2.start()
t1.start()
k = -1
t1.join()
t2.join()
else:
if __name__ == '__main__':
t1 = threading.Thread(target = light, args = (i,))
t2 = threading.Thread(target = sound, args = (i,))
t2.start()
t1.start()
t1.join()
t2.join()
j = - 1
if i in [0,1,2,4]:
k = i
os.system('omxplayer --threshold 0 -o both /home/pi/Music/more.mp3')
else:
k = -1
if not current_touched & pin_bit and last_touched & pin_bit:
print('{0} released!'.format(i))
# Update last state and wait a short period before repeating.
last_touched = current_touched
time.sleep(0.1)