Last active
October 8, 2019 13:10
-
-
Save rowena-s/a7f82f606668547baa7c5b057e919e2c to your computer and use it in GitHub Desktop.
8 notes, 3 pins, 2 buttons. What do?
This file contains hidden or 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
/* | |
JavaScript code to play a C major scale on the microbit. Pin0 is reserved for the sound output device. | |
So really we have 2 pins and 2 buttons | |
P1 = C3, P2 = D3, A = E3, B = F3, A+P1=G3 A+P2 =A3 , B+P1 =B3 , B+P2=C4 (values in code are actually hz) | |
######################## | |
Copy the code below into https://makecode.microbit.org/#editor in Javascript mode. | |
You can switch to Blocks mode if you're not comfortable with Javscript code. | |
*/ | |
basic.forever(function () { | |
if (input.buttonIsPressed(Button.A)) { | |
if (input.pinIsPressed(TouchPin.P1)) { | |
basic.showString("G") | |
music.playTone(392, music.beat(BeatFraction.Whole)) | |
} else if (input.pinIsPressed(TouchPin.P2)) { | |
basic.showString("A") | |
music.playTone(440, music.beat(BeatFraction.Whole)) | |
} else { | |
basic.showString("E") | |
music.playTone(330, music.beat(BeatFraction.Half)) | |
} | |
} else if (input.buttonIsPressed(Button.B)) { | |
if (input.pinIsPressed(TouchPin.P1)) { | |
basic.showString("B") | |
music.playTone(494, music.beat(BeatFraction.Whole)) | |
} else if (input.pinIsPressed(TouchPin.P2)) { | |
basic.showString("C") | |
music.playTone(523, music.beat(BeatFraction.Whole)) | |
} else { | |
basic.showString("F") | |
music.playTone(349, music.beat(BeatFraction.Whole)) | |
} | |
} else if (input.pinIsPressed(TouchPin.P1)) { | |
basic.showString("C") | |
music.playTone(262, music.beat(BeatFraction.Whole)) | |
} else if (input.pinIsPressed(TouchPin.P2)) { | |
basic.showString("D") | |
music.playTone(294, music.beat(BeatFraction.Whole)) | |
} else { | |
basic.showIcon(IconNames.EigthNote) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment