This program turns the micro:bit into a storytelling friend that reacts to different body movements using AI. The micro:bit is trained to recognise actions such as walking, jumping, rolling, and sleeping. Whenever one of these actions starts or stops, the micro:bit responds with sounds and pictures, making it feel interactive and alive.
When the micro:bit detects that a person has started walking, it plays a cheerful tune. This makes walking feel like part of a story, as if the character has begun a journey. When walking stops, all sounds are stopped so that the micro:bit stays quiet and ready for the next action.
When jumping is detected, the micro:bit shows a surprised face and plays a giggling sound. This reaction matches the excitement of jumping. Once the jumping stops, the micro:bit stops all sounds so the story does not continue unnecessarily.
When the person rolls, the micro:bit shows a simple shape on the screen and plays music in the background. This creates a playful effect while the action continues. As soon as rolling stops, the sound is stopped to keep the behavior controlled.
When the micro:bit senses sleeping, it shows a sleeping icon and plays a soft, calming sound. This makes the micro:bit behave gently, just like a character going to sleep. When sleeping ends, the sound stops so the device does not keep playing music.
If the micro:bit detects an unknown action, it clears the screen. This shows that the device is unsure and waits calmly until it understands the next movement.
Overall, this program uses Artificial Intelligence to recognize actions and react in a meaningful way. It combines movement detection, sounds, and images to create an engaging storytelling experience. The micro:bit behaves like a friendly character that reacts differently to each action, helping students understand how AI can make technology smart and interactive
def on_on_stop():
music.stop_all_sounds()
ml.on_stop(ml.event.jumping, on_on_stop)
def on_on_stop2():
music.stop_all_sounds()
ml.on_stop(ml.event.sleeping, on_on_stop2)
def on_on_stop3():
music.stop_all_sounds()
ml.on_stop(ml.event.walking, on_on_stop3)
def on_on_start():
music.play(music.string_playable("E F G G A A B B ", 129),
music.PlaybackMode.UNTIL_DONE)
ml.on_start(ml.event.walking, on_on_start)
def on_on_start2():
basic.show_icon(IconNames.SURPRISED)
music.play(music.builtin_playable_sound_effect(soundExpression.giggle),
music.PlaybackMode.UNTIL_DONE)
ml.on_start(ml.event.jumping, on_on_start2)
def on_on_start3():
basic.show_icon(IconNames.SQUARE)
music.play(music.string_playable("C5 B A G F E D C ", 446),
music.PlaybackMode.IN_BACKGROUND)
ml.on_start(ml.event.rolling, on_on_start3)
def on_on_start4():
basic.show_icon(IconNames.ASLEEP)
music.play(music.builtin_playable_sound_effect(soundExpression.twinkle),
music.PlaybackMode.UNTIL_DONE)
ml.on_start(ml.event.sleeping, on_on_start4)
def on_on_stop4():
music.stop_all_sounds()
ml.on_stop(ml.event.rolling, on_on_stop4)
def on_on_start5():
basic.clear_screen()
ml.on_start(ml.event.unknown, on_on_start5)