Skip to content

Instantly share code, notes, and snippets.

@IowaDave
Last active June 14, 2018 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IowaDave/7b688c6f236d983c64f29e741b720d46 to your computer and use it in GitHub Desktop.
Save IowaDave/7b688c6f236d983c64f29e741b720d46 to your computer and use it in GitHub Desktop.
Shake Event Example Code
// ********************************************
// 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