Skip to content

Instantly share code, notes, and snippets.

@Hackin7
Created July 23, 2018 11:47
Show Gist options
  • Save Hackin7/34fc0be43dbc654c13c2c61f1140bc14 to your computer and use it in GitHub Desktop.
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
//
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