Example Code for MakeCode-micro:bit-Digital Value Display

Use a Photo Interrupter for detection and display the detected digital value on the micro:bit's LED matrix.

Hardware Preparation

Software Preparation

Wiring Diagram

Connect the Photo Interrupter to the P2 pin on the IO Extender for micro:bit, as shown in the diagram below.

Sample Code

Result

When the program is successfully downloaded, block the Photo Interrupter with an object. The indicator light on the sensor will turn on, and the micro:bit LED matrix will display 1. When the object is removed, the indicator light on the sensor will turn off, and the micro:bit LED matrix will display 0.

Was this article helpful?

TOP