Case 5: Adjustable light ring
Introduction:
Use the rotary encoder to control the brightness of the light ring, and set the color of the light ring through the "A" or "B" button of the micro:bit.
Purpose of the case:
Understand the rotary encoder and its working principle.
Understand the rotary encoder programming building blocks in MakeCode.
Materials required:
| Item | Picture | Quantity |
|---|---|---|
| micro:bit V2 | ![]() | 1 |
| Jacdac expansion board | ![]() | 1 |
| Jacdac 10cm connection wire | ![]() | 2 |
| Knob Encoder | ![]() | 1 |
| Light Ring | ![]() | 1 |
| USB Cable | ![]() | 1 |
Sensor principle description:

Principle description:
Rotary encoder: A sensor used to detect the direction and value of rotational motion.

Principle description:
Light ring: a circular light ring composed of 8 RGB lights.
Connection diagram
As shown in the figure below, insert the micro:bit into the Jacdac expansion board, and use the connecting wire to connect the rotary encoder sensor and the light ring in a star shape to the gold finger interface of the Jacdac expansion board.

Programming software
Makecode programming
Step 1: How to add Jacdac extension
- Enter Microsoft Makecode and click "New Project".

- In the pop-up window, enter a project name and click Create.

- Click "Extend" in the code drawer.

- In the pop-up interface, enter "Jacdac" and click the search icon, select the Jacdac software library, as shown in the figure.

Step 2:
- Connect micro:bit to the computer with a data cable.
Note: If the micro:bit is running the Jacdac program for the first time, please pre-install a blank Jacdac program on the motherboard, otherwise skip this step.

- Connect the sensor, MakeCode will automatically identify and simulate it, and the sensor will provide real-time feedback of the sensor status in the simulation area.

Click on "ADD BLOCKS" sensor expansion module.
Note: To connect a new sensor, repeat the "Click on "ADD BLOCKS" sensor expansion module" operation process.

Write the program as shown

Reference program link:
https://makecode.microbit.org/_XcUA7T3VAAM8
You can also download the program directly from the following webpage, and start running the program after downloading.
Result
Use the knob encoder to adjust the brightness of the light ring, and press the micro:bit motherboard buttons A and B to switch the color of the light ring.

Thinking
How to switch more colors of the light ring using the micro:bit buttons A and B。
.png)




