Created
July 23, 2018 11:47
-
-
Save Hackin7/34fc0be43dbc654c13c2c61f1140bc14 to your computer and use it in GitHub Desktop.
From https://makecode.microbit.org , for a DIY toy gun with speaker and PIR sensor
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
// | |
let item = 0 | |
input.onButtonPressed(Button.B, () => { | |
pins.digitalWritePin(DigitalPin.P13, 1) | |
item = 1 | |
basic.showIcon(IconNames.Yes) | |
}) | |
input.onButtonPressed(Button.A, () => { | |
music.playTone(440, music.beat(BeatFraction.Sixteenth)) | |
item = 0 | |
pins.digitalWritePin(DigitalPin.P13, 0) | |
basic.showIcon(IconNames.No) | |
}) | |
basic.forever(() => { | |
if (pins.digitalReadPin(DigitalPin.P16) == 1) { | |
music.playTone(pins.analogReadPin(AnalogPin.P1), music.beat(BeatFraction.Whole)) | |
} | |
if (pins.digitalReadPin(DigitalPin.P15) == 1 && 1 == item) { | |
music.playTone(pins.analogReadPin(AnalogPin.P1), music.beat(BeatFraction.Double)) | |
basic.showIcon(IconNames.Square) | |
} else { | |
basic.showLeds(` | |
. . . . . | |
. . . . . | |
. . . . . | |
. . . . . | |
. . . . . | |
`) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment