Skip to content

Instantly share code, notes, and snippets.

@IowaDave
Last active June 14, 2018 20:56
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/0fe5bc4464d6371eab7c80aa3775883c to your computer and use it in GitHub Desktop.
Save IowaDave/0fe5bc4464d6371eab7c80aa3775883c to your computer and use it in GitHub Desktop.
Motion_Switches
// ****************************************************************
// Motion Switches | MakerBit Example Code
// To demonstrate using a micro:bit controller with the
// Tilt, Shock, and Tap modules in the 37 Sensors Kit V 2.0
// from Elegoo
//
// Copy and paste into the JavaScript side of the Microsoft
// MakeCode browser-based editor for micro:bit.
//
// by David Sparks June 14, 2018
// ****************************************************************
//
// Turn off the LED at the Start
pins.digitalWritePin(DigitalPin.P16, 0)
// The main loop checks the switch connected to pin P8
// and operates the LED.
basic.forever(() => {
if (pins.digitalReadPin(DigitalPin.P8) >= 1)
{
// the switch closes when the module detects motion
// turn on the LED
pins.digitalWritePin(DigitalPin.P16, 1)
basic.pause(200)
}
else
{
// the switch opens when the module is not sensing motion
// turn off the LED
pins.digitalWritePin(DigitalPin.P16, 0)
basic.pause(200)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment