When feeling sad, a purple-pink light surrounds me. Its soft glow feels like a warm embrace, gently soothing my heart. When happy, the orange light shines like sunlight—warm and comforting. During family gatherings, turn on party mode: the blue chasing lights perfectly express the joy in my heart, making the atmosphere even more lively. When listening to music, the changing neon lights make it feel as if I’m at a live concert.
The Mood Ambiance Light has gone beyond the concept of an ordinary “lamp”.It is not just a lighting tool but also a pleasant addition to life, creating a wonderful atmosphere for every moment. You can switch between different lighting effects to match various moods and scenarios—an experience that’s truly amazing! Next, let’s use the UNIHIKER M10 and an RGB light ring to make a Mood Ambiance Light that adjusts automatically to mood and scene.

Goal
Each expression on the Mood Ambiance Light interface corresponds to a specific lighting effect:
Tap the sad expression → the RGB light ring displays purple-pink.
Tap the happy expression → it displays orange.
Tap the dancing expression → it shows blue chasing lights.
Tap the music expression → it cycles through random colors.

Get to Know
1.Understand random numbers
2.Learn how to use the RGB light ring.
3.Understand the working principle of RGB lights.
Material List
Hardware list:

Software:
Mind+ Programming Software x1(download at https://mindplus.cc/en)

Hands-on Practice
The mood ambiance light is divided into two modes: Mood Mode and Scene Mode. Mood Mode allows switching of light colors based on the sad and happy expressions; Scene Mode enables switching of light effects according to the dancing and music expressions. Next, let’s learn how to make a mood ambiance light through the following two small tasks.
Task 1: Make the Mood Light
Use image materials to complete the design of the mood ambiance light’s control interface, and add light display functions for the sad and happy expressions. Tap the sad expression, and the RGB light ring will display purple-pink; tap the happy expression, and the RGB light ring will show orange.
Task 2: Make the Scene Light
Based on Task 1, design light effects for the two Scene Modes (dancing and music). Tap the dancing expression, and the RGB light ring will present blue chasing lights; tap the music expression, and the RGB light ring will switch to random colors.
Task 1: Make the Mood Light
1.Hardware Connection
Use a white silicone wire to connect the IN interface of the RGB light ring to the P24 pin of the UNIHIKER M10. After the hardware connection is successful, use a USB cable to connect the UNIHIKER M10 to the computer.
Note: For relevant introductions about the "RGB light ring", please refer to the Knowledge Base.

2.Software Preparation
Open Mind+ and follow the diagram below to complete the software preparation process.

Add the WS2812 RGB LED library. Click "Extension", find "WS2812 RGB LED" in the pinpong library and click it to complete the addition.

3.Write a Program
Before starting to write the program, let's first analyze the main functions to be implemented in this task. First, the control interface of the mood ambiance light will be displayed on the UNIHIKER M10. Then, through the sad and happy expressions on the interface, the RGB light ring can be controlled to display different light colors. The objects used in the control interface of the mood ambiance light and their corresponding coordinates are shown in the figure below.
(1)Design the control interface
To design the control interface of the mood ambiance light on the UNIHIKER M10, you first need to import the background and expression images from the image folder into the file system.

Use the i“mage display” block to show the background and expression images on the UNIHIKER M10. Simply set the images to be displayed at their corresponding X and Y coordinates based on the image coordinates analyzed above.

Then use the text display block to show "Mood Ambiance Light" on the UNIHIKER M10. By “updating the reference point to the center” block, set the text to display directly above the background pattern.

(2)Create the light display
In this task, the main goal is to implement the light display for the sad and happy expressions.Therefore, use “the click callback function” block and when “the click callback function “ block to add click callback functions to the "sad" and "smile" objects.

To use the RGB light ring, you first need to use the RGB light initialization block below the start of the Python main program to “initialize the pin of the RGB” light ring and the number of LEDs in the light ring.

From the hardware connection diagram, you can see that the light ring is connected to the P24 pin of the UNIHIKER M10. Next, use the pin block in the “UNIHIKER pin” operations, select the P24 pin, then place this block into the pin parameter of the RGB light initialization block, and finally set the number of lights to 12.
Note: For relevant introductions about the "RGB light ring", please refer to the Knowledge Corner.

Next, it is necessary to set the color of the RGB light ring under the "when the click callback function is triggered" block. Taking the callback function "button_click1" as an example, when the sad expression is clicked, use the "set light ring color" block to set the color of the RGB light ring to magenta.
Observant students will quickly notice that the RGB light ring we're using has 12 LED beads, but no matter how we set it, only one bead lights up. To make all 12 beads of the light ring light up, what should we do? Use a “for loop” (Use my variable from range0 to 11 every 1) block, set the range from 0 to 11 with a step of 1, and use the variable "my variable" to control each bead to display magenta.

The other callback function "button_click2" sets the display color of the light ring to orange in the same way. The complete program is as follows:

4.Run the Program
Click to run. After the program runs successfully, click the sad expression on the UNIHIKER M10 screen, and the RGB light ring will display magenta; click the happy expression, and the RGB light ring will display orange. The UNIHIKER M10 interface and the display effect diagram of the RGB light ring are as follows:

Task 2: Make the Scene Light
1.Write a Program
On the basis of the previous task, add click callback functions for the dancing and music expressions.

(1)Create a running light
What is a running light? A running light is a light effect where only one LED bead lights up at a time, and it cycles at an extremely fast speed, making it look like the bead is running around the light ring like a horse. In Task 1, to make all the RGB light ring beads light up, we used a “for loop” to make the light ring go from having no beads lit, to one bead lit, then a second, until all 12 beads were lit. For a running light, only one bead is lit at a time. We can also use a for loop block: make a bead light up for 0.1 seconds, then turn it off. This way, we can achieve the running light effect. To turn off an RGB light, use the "set light ring color" block and set the display color of the bead to black.

Although the above program realizes the effect of blue LED beads "running" around the light ring like a horse, it stops executing after the beads finish one full cycle. Let's think: is there a good way to make the beads repeat the above operation after finishing a cycle?
We can use the method of a flag variable, placing the running light program in a repeat execution block. Create a new variable "flag" and initialize it to 0. Then, under the "when the click callback function button_click3 is triggered" block, define the variable "flag" as a global variable. When the callback function is triggered, set the value of variable "flag" to 3.

Then, in the “forever” block, use a conditional judgment block to check if the callback function has been triggered (is variable flag equal to 3?). If yes, execute the running light program.

(2)Create a neon light
Next, let's create a changing neon light, making the light ring cycle through random colors at intervals. First, under the "when the click callback function button_click4 is triggered" block, define the flag variable as a global variable and set the value of variable flag to 4.

In the “forever” block, use a conditional judgment block to check if the callback function has been triggered (is variable flag equal to 4?). If yes, make the RGB light ring display changing neon lights.

How can we make the RGB light ring change colors? Using the "Set Light Ring Color" block only allows selecting specific colors from the block's predefined options, and it cannot achieve random color changes. There is also an “red-green-blue” block in the light strip block area, which uses the principle of RGB primary color mixing. By mixing these three colors (red, green, and blue), more different colors can be obtained. These two blocks can be used together.

Next, we will set the color of the light ring by changing the values of red, green, and blue. Create new variables R, G, and B respectively, and initialize their values to 0 under the start of the Python main program. Then, when the callback function is triggered, use the random number block in the numeric type to make these three variables generate a random integer between 0 and 255 respectively.
Note: For relevant introductions about "random numbers", please refer to the Knowledge Corner.

Finally, place “variables R, G, and B” into the “red-green-blue” block respectively. The complete program is as follows:

2.Run the Program
Click to run. After the program runs successfully, click the sad expression on the interface, and the RGB light ring will display magenta; click the happy expression, and the RGB light ring will display orange; click the dancing expression, and the RGB light ring will show a blue flowing light effect; click the music expression, and the RGB light ring will cycle through random colors.

3.Have a try
The above program enables switching between different lighting effects by clicking on mood expressions. However, if you switch the lighting effects several times, you'll notice that once we switch to the dancing and music lighting effects, we can't switch back to the sad and happy lighting effects. This is because the dancing and music lighting effects are in loop blocks, while the sad and happy lighting effects are under callback functions. Next, try to modify the above program to realize that the lighting effects can be switched freely.
Hint: Use the flag variable method to implement the sad and happy lighting effects in the loop execution block.
Knowledge Base
1.Understanding Random Numbers
What is a random number? A random number can be simply understood as a random numerical value. It is selected from a set of possible values, and each possible value has the same probability of being selected. For example, many people have played dice games—the number obtained by rolling a die is a random number between 1 and 6.

For example, in the following program, the random number block is used to set the range of random numbers from 1 to 10. This block is like a 10-sided die, and the number generated by rolling the die is the random number generated by this block.

2.Understanding RGB Lights
What is an RGB light? An RGB light is actually a type of LED light. Inside an RGB light, three LEDs (red, green, and blue) are integrated. By adjusting the brightness of each of these three LEDs, different colors can be produced, allowing the RGB light ring to display a variety of colors.

An RGB light ring has two interfaces: an IN interface and an OUT interface. The one connected in the project is the IN interface, which is used to control the output of the RGB light ring; the OUT interface is used for cascading between light rings. How to cascade RGB light rings? Use a white silicone wire to connect the OUT interface of one light ring to the IN interface of another light ring.

How to use an RGB light ring? How to achieve color changing? An RGB light incorporates three color LEDs (red, green, and blue) into a single light bead, and this bead can be used as three separate lights. To set an RGB light to display different colors, you can use the "Set RGB Light Color" block to select colors. The "Set RGB Light Color" block encapsulates the RGB values of commonly used colors into corresponding color options for our use.

However, the number of colors that a light ring can display is far greater than the colors included in this block. Therefore, by using the red-green-blue block, you can generate all colors within the range of 0-255, totaling 16,777,216 colors (calculated as 256×256×256).

Both of these blocks use the principle of RGB primary colors. For students who are interested, you can try it out by adjusting different values in the red-green-blue block to switch colors.

3.Blocks Overview

Challenge
In the light effect synchronized with musical expression, the RGB light ring will cycle through random colors. Next, everyone should modify the program based on the existing one: change the neon light effect to a rainbow light effect. During the process of lighting up the light beads in a cycle, set each light bead to a different color, so as to make the RGB light ring look just like a rainbow. The display effect of the RGB light ring is shown in the figure below:
Tip: Place the blocks for generating random numbers for variables R, G, and B into the for loop block.








