Guest User

Untitled

a guest
Jun 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. // ******************************************************
  2. // Push button with pull-up resistor | MakerBit example
  3. //
  4. // To demonstrate using a micro:bit with the push-button
  5. // module in the 37-Sensors kit by Elegoo.
  6. // The module has a built-in pull-up resistor, so
  7. // the signal pin is HIGH when the button is NOT pressed.
  8. // Pressing the button grounds the signal pin to LOW.
  9. //
  10. // Target: MakeCode Javascript editor for micro:bit
  11. //
  12. // David Sparks June 21, 2018
  13. // ***************************************************
  14. //
  15. // Setup
  16. let ButtonState = 0
  17. ButtonState = pins.digitalReadPin(DigitalPin.P8)
  18. pins.digitalWritePin(DigitalPin.P16, 0)
  19. // Loop
  20. basic.forever(() => {
  21. ButtonState = pins.digitalReadPin(DigitalPin.P8)
  22. if (ButtonState > 0) {
  23. pins.digitalWritePin(DigitalPin.P16, 0)
  24. } else {
  25. pins.digitalWritePin(DigitalPin.P16, 1)
  26. }
  27. })
Add Comment
Please, Sign In to add comment