67
67
mpr121 = adafruit_mpr121 .MPR121 (i2c )
68
68
69
69
# Demo MODE LED Animations ------------------------------------------------------
70
- rainbow = Rainbow (pixels , speed = 0.1 , period = 10 , name = "rainbow" , step = 1 )
70
+ rainbow = Rainbow (pixels , speed = 0 , period = 10 , name = "rainbow" , step = 1 )
71
71
rainbow_chase = RainbowChase (pixels , speed = 0 , size = 5 , spacing = 10 )
72
72
chase = Chase (pixels , speed = 0.1 , color = RED , size = 1 , spacing = 6 )
73
73
rainbow_comet = RainbowComet (pixels , speed = 0.01 , tail_length = 60 , bounce = True )
@@ -102,21 +102,22 @@ def go_dark():
102
102
audio = AudioOut (board .SPEAKER )
103
103
104
104
tracks = (
105
- WaveFile (open ("sounds/F1.wav" , "rb" )), # 0
106
- WaveFile (open ("sounds/G1.wav" , "rb" )), # 1
107
- WaveFile (open ("sounds/A1.wav" , "rb" )), # 2
108
- WaveFile (open ("sounds/Bb1.wav" , "rb" )), # 3
109
- WaveFile (open ("sounds/C1.wav" , "rb" )), # 4
110
- WaveFile (open ("sounds/D2.wav" , "rb" )), # 5
111
- WaveFile (open ("sounds/E2.wav" , "rb" )), # 6
112
- WaveFile (open ("sounds/F2.wav" , "rb" )), # 7
113
- WaveFile (open ("sounds/G2.wav" , "rb" )), # 8
114
- WaveFile (open ("sounds/A2.wav" , "rb" )), # 9
115
- WaveFile (open ("sounds/Bb2.wav" , "rb" )), # 10
116
- WaveFile (open ("sounds/C2.wav" , "rb" )), # 11
117
- WaveFile (open ("sounds/D3.wav" , "rb" )), # 12
118
- WaveFile (open ("sounds/E3.wav" , "rb" )), # 13
119
- WaveFile (open ("sounds/F3.wav" , "rb" )), # 13
105
+ WaveFile (open ("sounds/F2.wav" , "rb" )), # 0
106
+ WaveFile (open ("sounds/G2.wav" , "rb" )), # 1
107
+ WaveFile (open ("sounds/A2.wav" , "rb" )), # 2
108
+ WaveFile (open ("sounds/Bb2.wav" , "rb" )), # 3
109
+ WaveFile (open ("sounds/C2.wav" , "rb" )), # 4
110
+ WaveFile (open ("sounds/D3.wav" , "rb" )), # 5
111
+ WaveFile (open ("sounds/E3.wav" , "rb" )), # 6
112
+ WaveFile (open ("sounds/F3.wav" , "rb" )), # 7
113
+ WaveFile (open ("sounds/F1.wav" , "rb" )), # 7
114
+ WaveFile (open ("sounds/G1.wav" , "rb" )), # 8
115
+ WaveFile (open ("sounds/A1.wav" , "rb" )), # 9
116
+ WaveFile (open ("sounds/Bb1.wav" , "rb" )), # 10
117
+ WaveFile (open ("sounds/C1.wav" , "rb" )), # 11
118
+ WaveFile (open ("sounds/D2.wav" , "rb" )), # 12
119
+ WaveFile (open ("sounds/E2.wav" , "rb" )), # 13
120
+ WaveFile (open ("sounds/F2.wav" , "rb" )), # 13
120
121
)
121
122
122
123
# Add or change song track names here. They will play in the order listed.
@@ -146,7 +147,7 @@ def play_bottle(bottle_id, is_octave):
146
147
light_up (bottle_id )
147
148
if is_octave :
148
149
audio .play (tracks [bottle_id + 7 ]) # Start playing sound
149
- light_up (9 )
150
+ light_up (8 )
150
151
else :
151
152
audio .play (tracks [bottle_id ]) # Start playing sound
152
153
pixels .show ()
@@ -157,6 +158,7 @@ def check_buttons(touched):
157
158
''' check to see if buttons have been pressed'''
158
159
global MODE , LAST_BUTTON
159
160
octave = touched [11 ]
161
+ off = touched [9 ]
160
162
if octave :
161
163
light_up (8 )
162
164
for pad in range (1 , 9 ):
@@ -165,7 +167,7 @@ def check_buttons(touched):
165
167
if pad != LAST_BUTTON and touched [pad ]:
166
168
LAST_BUTTON = pad
167
169
play_bottle (pad - 1 , octave )
168
- if touched [ 9 ] :
170
+ if off :
169
171
MODE = 9
170
172
go_dark ()
171
173
if touched [10 ]:
@@ -180,10 +182,12 @@ def check_buttons(touched):
180
182
while True :
181
183
# Idle mode: Play a Rainbow animation when nothing's being touched
182
184
if MODE == 0 :
183
- pixels .brightness = 1 #rainbow mode is much brighter than the other modes, so adjust here
185
+ pixels .brightness = 0.3 #rainbow mode is much brighter than the other modes, so adjust here
184
186
rainbow .animate ()
185
187
for button in buttons :
186
188
button .update ()
189
+ check_buttons (mpr121 .touched_pins )
190
+ time .sleep (0.1 )
187
191
for i in range (12 ):
188
192
if buttons [i ].fell :
189
193
MODE = 1
@@ -210,8 +214,8 @@ def check_buttons(touched):
210
214
else :
211
215
MODE = 0 # Return to idle mode
212
216
if MODE == 9 : # MODE 9 is "off" mode, listening for a new button press to wake up.
213
- for button in buttons :
214
- button .update ()
217
+ # for button in buttons:
218
+ # button.update()
215
219
for i in range (12 ):
216
220
if buttons [i ].fell :
217
221
MODE = 1
0 commit comments