Skip to content

Commit 8d171f7

Browse files
authored
Merge branch 'master' into blinka-pwm
2 parents e8a20ab + 53650d3 commit 8d171f7

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

Glowing_Bottle_Castle/code.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
mpr121 = adafruit_mpr121.MPR121(i2c)
6868

6969
# 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)
7171
rainbow_chase = RainbowChase(pixels, speed=0, size=5, spacing=10)
7272
chase = Chase(pixels, speed=0.1, color=RED, size=1, spacing=6)
7373
rainbow_comet = RainbowComet(pixels, speed=0.01, tail_length=60, bounce=True)
@@ -102,21 +102,22 @@ def go_dark():
102102
audio = AudioOut(board.SPEAKER)
103103

104104
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
120121
)
121122

122123
# 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):
146147
light_up(bottle_id)
147148
if is_octave:
148149
audio.play(tracks[bottle_id + 7]) # Start playing sound
149-
light_up(9)
150+
light_up(8)
150151
else:
151152
audio.play(tracks[bottle_id]) # Start playing sound
152153
pixels.show()
@@ -157,6 +158,7 @@ def check_buttons(touched):
157158
''' check to see if buttons have been pressed'''
158159
global MODE, LAST_BUTTON
159160
octave = touched[11]
161+
off = touched[9]
160162
if octave:
161163
light_up(8)
162164
for pad in range(1, 9):
@@ -165,7 +167,7 @@ def check_buttons(touched):
165167
if pad != LAST_BUTTON and touched[pad]:
166168
LAST_BUTTON = pad
167169
play_bottle(pad - 1, octave)
168-
if touched[9]:
170+
if off:
169171
MODE = 9
170172
go_dark()
171173
if touched[10]:
@@ -180,10 +182,12 @@ def check_buttons(touched):
180182
while True:
181183
# Idle mode: Play a Rainbow animation when nothing's being touched
182184
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
184186
rainbow.animate()
185187
for button in buttons:
186188
button.update()
189+
check_buttons(mpr121.touched_pins)
190+
time.sleep(0.1)
187191
for i in range(12):
188192
if buttons[i].fell:
189193
MODE = 1
@@ -210,8 +214,8 @@ def check_buttons(touched):
210214
else:
211215
MODE = 0 # Return to idle mode
212216
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()
215219
for i in range(12):
216220
if buttons[i].fell:
217221
MODE = 1

0 commit comments

Comments
 (0)