Lintang Wisesa
Published © GPL3+

Micro:bit Tone Player

A simple tone player using BBC Micro:bit boards.

BeginnerFull instructions provided1 hour759
Micro:bit Tone Player

Things used in this project

Hardware components

BBC micro:bit board
BBC micro:bit board
×1
Alligator Clips
Alligator Clips
×3
Speaker: 3W, 4 ohms
Speaker: 3W, 4 ohms
×1

Software apps and online services

MakeCode
Microsoft MakeCode

Story

Read more

Code

Micro:bit Tone Player

JavaScript
let lagu = 0

input.onButtonPressed(Button.B, () => {
    if (lagu == 5) {
        lagu = 1
        basic.showNumber(lagu)
        music.beginMelody(music.builtInMelody(Melodies.Entertainer), MelodyOptions.Once)
    } else {
        lagu = lagu + 1
        basic.showNumber(lagu)
        if (lagu == 1) {
            music.beginMelody(music.builtInMelody(Melodies.Entertainer), MelodyOptions.Once)
        } else if (lagu == 2) {
            music.beginMelody(music.builtInMelody(Melodies.Blues), MelodyOptions.Once)
        } else if (lagu == 3) {
            music.beginMelody(music.builtInMelody(Melodies.Nyan), MelodyOptions.Once)
        } else if (lagu == 4) {
            music.beginMelody(music.builtInMelody(Melodies.Birthday), MelodyOptions.Once)
        } else {
            music.beginMelody(music.builtInMelody(Melodies.Wedding), MelodyOptions.Once)
        }
    }
})

input.onButtonPressed(Button.A, () => {
    if (lagu == 0) {
        lagu = 5
        basic.showNumber(lagu)
        music.beginMelody(music.builtInMelody(Melodies.Wedding), MelodyOptions.Once)
    } else {
        lagu = lagu - 1
        basic.showNumber(lagu)
        if (lagu == 1) {
            music.beginMelody(music.builtInMelody(Melodies.Entertainer), MelodyOptions.Once)
        } else if (lagu == 2) {
            music.beginMelody(music.builtInMelody(Melodies.Blues), MelodyOptions.Once)
        } else if (lagu == 3) {
            music.beginMelody(music.builtInMelody(Melodies.Nyan), MelodyOptions.Once)
        } else if (lagu == 4) {
            music.beginMelody(music.builtInMelody(Melodies.Birthday), MelodyOptions.Once)
        } else {
            music.beginMelody(music.builtInMelody(Melodies.Wedding), MelodyOptions.Once)
        }
    }
})

lagu = 0
music.beginMelody(music.builtInMelody(Melodies.PowerUp), MelodyOptions.Once)
basic.showIcon(IconNames.EigthNote)

basic.forever(() => {})

Credits

Lintang Wisesa

Lintang Wisesa

14 projects β€’ 68 followers
πŸ” Full Snack Develaper

Comments

Add projectSign up / LoginAbout BBC micro:bit