Last active
June 14, 2018 18:05
-
-
Save IowaDave/7b688c6f236d983c64f29e741b720d46 to your computer and use it in GitHub Desktop.
Shake Event Example Code
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
// ******************************************** | |
// MakerBit Example | Detect Shake Event | |
// | |
// Lights an LED connected to Pin P16 | |
// for 1/2 of a second | |
// after micro:bit raises a Shake event. | |
// | |
// Paste into the JavaScript area of the | |
// Microsoft MakeCode online blocks editor. | |
// | |
// by David Sparks June 14, 2018 | |
// ******************************************** | |
// | |
// This code detects and handles the Shake event | |
input.onGesture(Gesture.Shake, () => { | |
pins.digitalWritePin(DigitalPin.P16, 1) | |
basic.pause(500) | |
pins.digitalWritePin(DigitalPin.P16, 0) | |
}) | |
// | |
// This code will be in the Start block | |
pins.digitalWritePin(DigitalPin.P16, 0) | |
// | |
// The main loop actually does nothing | |
// because the action all takes place | |
// in the event handler, above. | |
basic.forever(() => { | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment