Play a Happy Birthday song with Micro:bit

Source: Internet
Author: User

Micro:bit comes with an interesting feature is the ability to generate music playback, today do a simple and practical case, with Micro:bit play Happy Birthday song.

algorithm:

Press the button A to show Happy birthday

play D

play D

play E

play D

play G

play F

rest

In order to play music, a buzzer or headset that works 3V can be connected to the Micro:bit Gnd and Pine0 feet, such as

blocky program is as follows

micropython program script is as follows:

from microbit Import *

import music

 tune = [" E4:4 "," E4:4 "," E4:8 "," E4:4 "," E4:4 "," E4:8 "," E4:4 "," G4:4 "," C4:4 "," D4:4 "," E4:8 "," F4:4 "," F4:4 "," F4:4 "," F4:4 "," F4:4 ",

" E4:4 "," E4:4 "," E4:2 "," E4:2 "," E4:4 "," D4:4 "," D4:4 "," E4:4 "," D4:8 "," G4:8 "," E4:4 "," E4:4 ", "E4:8", "E4:4", "E4:4", "E4:8",

" E4:4 "," G4:4 "," C4:4 "," D4:4 "," E4:8 "," F4:4 "," F4:4 "," F4:4 "," F4:4 "," F4:4 "," E4:4 "," E4:4 ", "E4:2", "E4:2", "G4:4", "G4:4",

" F4:4 "," D4:4 "," C4:8 "]

 while True:

if button_a.is_pressed ():

music.play (tune)

download to play.

original reference

https:// mp.weixin.qq.com/s?__biz=mzu0mtg0odizna==&mid=2247484011&idx=1&sn=45a885492aa34f2b6c56a632d0ccb595 &chksm=fb22e5aecc556cb84933e0fb3be524da23f1e5641ab05f9e1daf0a62fd5826dd21ccdc1b5bb1#rd

Play a Happy Birthday song with Micro:bit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.