|
1 | 1 | import time
|
2 |
| -import board |
3 |
| -import digitalio |
4 | 2 | import displayio
|
5 |
| -import audiocore |
6 |
| -from audiopwmio import PWMAudioOut as AudioOut |
| 3 | +from adafruit_circuitplayground import cp |
7 | 4 | import adafruit_imageload
|
8 | 5 | from adafruit_gizmo import tft_gizmo
|
9 | 6 | from adafruit_display_shapes.circle import Circle
|
10 | 7 |
|
11 |
| -# setup for the speaker |
12 |
| -speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE) |
13 |
| -speaker_enable.switch_to_output(value=True) |
14 |
| - |
15 |
| -# setup for the CP Bluefruit's buttons |
16 |
| -button_a = digitalio.DigitalInOut(board.BUTTON_A) |
17 |
| -button_a.switch_to_input(pull=digitalio.Pull.DOWN) |
18 |
| - |
19 |
| -button_b = digitalio.DigitalInOut(board.BUTTON_B) |
20 |
| -button_b.switch_to_input(pull=digitalio.Pull.DOWN) |
21 |
| - |
22 | 8 | # setup for the Gizmo TFT
|
23 | 9 | display = tft_gizmo.TFT_Gizmo()
|
24 | 10 |
|
|
66 | 52 | # showing the main group on the display
|
67 | 53 | display.show(main_group)
|
68 | 54 |
|
69 |
| -# setting up the audio output |
70 |
| -speaker = AudioOut(board.SPEAKER) |
71 |
| -# importing the .wav file |
72 |
| -moonlight = "/moonlight_densetsu.wav" |
73 |
| -# function to open the .wav file |
74 |
| -data = open(moonlight, "rb") |
75 |
| -# decoding the .wav file |
76 |
| -wav = audiocore.WaveFile(data) |
77 |
| - |
78 | 55 | # tracks the tilegrid index location for the crescent moon
|
79 | 56 | moon = 0
|
80 | 57 | # holds time.monotonic()
|
|
90 | 67 |
|
91 | 68 | while True:
|
92 | 69 | # button debouncing
|
93 |
| - if not button_a.value and a_pressed: |
| 70 | + if not cp.button_a and a_pressed: |
94 | 71 | a_pressed = False
|
95 |
| - if not button_b.value and b_pressed: |
| 72 | + if not cp.button_b and b_pressed: |
96 | 73 | b_pressed = False
|
97 | 74 | # runs crescent moon animation
|
98 | 75 | if not music_playing and not animation_pause:
|
|
108 | 85 | if moon > 35:
|
109 | 86 | moon = 0
|
110 | 87 | # if music is NOT playing and you press the a button...
|
111 |
| - if not music_playing and (button_a.value and not a_pressed): |
| 88 | + if not music_playing and (cp.button_a and not a_pressed): |
112 | 89 | # music begins playing and will loop
|
113 |
| - speaker.play(wav, loop = True) |
114 |
| - a_pressed = True |
115 |
| - # music_playing state is updated |
116 | 90 | music_playing = True
|
117 |
| - # debugging REPL message |
118 |
| - print("music playing") |
119 |
| - # if music IS playing and you press the a button... |
120 |
| - if music_playing and (button_a.value and not a_pressed): |
121 |
| - # music stops |
122 |
| - speaker.stop() |
123 | 91 | a_pressed = True
|
| 92 | + print("music playing") |
| 93 | + # song plays once |
| 94 | + cp.play_file("moonlight_densetsu.wav") |
124 | 95 | # music_playing state is updated
|
125 | 96 | music_playing = False
|
126 |
| - # debugging REPL message |
127 |
| - print("music stopped") |
128 | 97 | # if the animation IS playing and you press the b button...
|
129 |
| - if not animation_pause and (button_b.value and not b_pressed): |
| 98 | + if not animation_pause and (cp.button_b and not b_pressed): |
130 | 99 | # the animation pauses by updating the animation_pause state
|
131 | 100 | animation_pause = True
|
132 | 101 | b_pressed = True
|
133 | 102 | # debugging REPL message
|
134 | 103 | print("animation paused")
|
135 | 104 | # if the animation is PAUSED and you press the b button...
|
136 |
| - if animation_pause and (button_b.value and not b_pressed): |
| 105 | + if animation_pause and (cp.button_b and not b_pressed): |
137 | 106 | # the animation begins again by updating the animation_pause state
|
138 | 107 | animation_pause = False
|
139 | 108 | b_pressed = True
|
|
0 commit comments