Skip to content

Commit 2823647

Browse files
committed
Updating code.py
Updating code.py with changes suggested by Jeff for mp3 library
1 parent 725a9e8 commit 2823647

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

LED_Matrix_Scoreboard/code.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@
6969
# setup for speaker pin
7070
speaker = audioio.AudioOut(board.A0)
7171

72+
# mp3 decoder setup
73+
file = "/hoopBloop0.mp3"
74+
mp3stream = audiomp3.MP3Decoder(open(file, "rb"))
75+
7276
# state machines used in the loop
7377
score = 0
7478
hoops = False
@@ -99,10 +103,8 @@
99103
score += 2
100104
# an mp3 plays
101105
file = "/hoopBloop{}.mp3".format(sample)
102-
mp3stream = audiomp3.MP3Decoder(open(file, "rb"))
106+
mp3stream.file = open(file, "rb")
103107
speaker.play(mp3stream)
104-
# delay for mp3, otherwise memory error
105-
time.sleep(0.5)
106108
print("score!")
107109
# resets break beam
108110
beam_state = False
@@ -118,16 +120,19 @@
118120
# score text x pos if 2 digit score
119121
elif score >= 10:
120122
score_text.x = 16
123+
elif score >= 0:
124+
score_text.x = 23
121125
# updates score text to show current score
122126
score_text.text = score
123-
time.sleep(0.1)
127+
time.sleep(0.01)
124128
# if a game is in progress and you press the button:
125129
if not button.value and hoops:
126130
# game stops
127131
hoops = False
128132
button_state = False
129133
# score is reset to 0
130134
score = 0
135+
score_text.text = score
131136
# display shows the start splash graphic
132137
display.show(start_group)
133138
print("end game!")

0 commit comments

Comments
 (0)