Skip to content

Instantly share code, notes, and snippets.

@IowaDave
Created June 21, 2018 19:00
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/d5f51bb9eda1902d2689447e9791006a to your computer and use it in GitHub Desktop.
Save IowaDave/d5f51bb9eda1902d2689447e9791006a to your computer and use it in GitHub Desktop.
Simple Push Button for MakerBit/MakeCode
// ******************************************************
// Push button with pull-up resistor | MakerBit example
//
// To demonstrate using a micro:bit with the push-button
// module in the 37-Sensors kit by Elegoo.
// The module has a built-in pull-up resistor, so
// the signal pin is HIGH when the button is NOT pressed.
// Pressing the button grounds the signal pin to LOW.
//
// Target: MakeCode Javascript editor for micro:bit
//
// David Sparks June 21, 2018
// ***************************************************
//
// Setup
let ButtonState = 0
ButtonState = pins.digitalReadPin(DigitalPin.P8)
pins.digitalWritePin(DigitalPin.P16, 0)
// Loop
basic.forever(() => {
ButtonState = pins.digitalReadPin(DigitalPin.P8)
if (ButtonState > 0) {
pins.digitalWritePin(DigitalPin.P16, 0)
} else {
pins.digitalWritePin(DigitalPin.P16, 1)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment