Code Example for micro:bit-Button Lamp

This article presents a comprehensive code example for creating a button-controlled lamp using a micro:bit, providing detailed hardware and software preparation steps, wiring diagrams, and sample programs in Mind+ and Makecode, enabling users to build an interactive LED project.

Hardware Preparation

BOS0002 Push Button Module BOS0017 LED Module
MBT0039 Micro:bit BOS0040 Micro:bit BOSON Expansion Board

Tips: micro:bit and Micro:bit BOSON expansion boards are used in the programming example.

Software Preparation

  • Development Tools: Mind+ or Makecode
  • Mind+ Download Link: Mind+
  • Makecode Download Link: Makecode

Wiring Diagram

Connection 2

Other Preparation Work

  1. Connect the micro:bit to the BOS0040 Micro:bit BOSON Expansion Board.
  2. Ensure all components are properly wired as per the diagram.

Sample Code

Mind+ Sample Program

Mind+1

Result

The LED turns on when the button is pressed and off when released. Refer to the demo video:

Additional Information

Flow Chart:

Was this article helpful?

TOP