-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust build and samples for record/playback No HAL changes but the API has changed
- Loading branch information
1 parent
34e45b3
commit 7d84c58
Showing
7 changed files
with
94 additions
and
29 deletions.
There are no files selected for viewing
Submodule micropython-microbit-v2
updated
43 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from microbit import * | ||
|
||
mouth_open = Image( | ||
"09090:" | ||
"00000:" | ||
"09990:" | ||
"90009:" | ||
"09990" | ||
) | ||
mouth_closed = Image( | ||
"09090:" | ||
"00000:" | ||
"00000:" | ||
"99999:" | ||
"00000" | ||
) | ||
play = Image( | ||
"00000:" | ||
"04740:" | ||
"07970:" | ||
"04740:" | ||
"00000" | ||
) | ||
|
||
my_recording = audio.AudioRecording(duration=5000) | ||
|
||
while True: | ||
if button_a.is_pressed(): | ||
my_track = microphone.record_into(my_recording, wait=False) | ||
display.show([mouth_open, mouth_closed], loop=True, wait=False, delay=150) | ||
while button_a.is_pressed() and microphone.is_recording(): | ||
sleep(50) | ||
microphone.stop_recording() | ||
display.show(mouth_closed) | ||
while button_a.is_pressed(): | ||
sleep(50) | ||
display.clear() | ||
# amplify volume | ||
GAIN = 2 | ||
#my_recording *= GAIN | ||
for i in range(len(my_track)): | ||
my_track[i] = max(0, min(128 + GAIN * (my_track[i] - 128), 255)) | ||
if button_b.is_pressed(): | ||
audio.play(my_track, wait=False) | ||
level = 0 | ||
while audio.is_playing(): | ||
l = audio.sound_level() | ||
if l > level: | ||
level = l | ||
else: | ||
level *= 0.95 | ||
display.show(play * min(1, level / 100)) | ||
x = accelerometer.get_x() | ||
my_track.set_rate(max(2250, scale(x, (-1000, 1000), (2250, 13374)))) | ||
sleep(5) | ||
display.clear() | ||
sleep(100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters