Project 15:Interactive RGB Light Show

As of the last class, our learning about external actuators for the UNIHIKER K10 ended. In this class, we'll use the onboard RGB light and A/B buttons for a comprehensive design, realizing the function of controlling different lighting effects with different buttons to create an interactive RGB light show. 


Project Objectives


Knowledge Objectives


1.Understand RGB color mixing principles.
2. Master the usage of the A/B buttons and RGB light on the UNIHIKER K10.
3.Gain an initial understanding of on-board actuators.


Practical Objective 


Create a light show with buttons and RGB light: Press A to turn on the UNIHIKER K10's RGB light in three colors (yellow, green, blue); press B to make the RGB light randomly light up in different colors; press A+B to turn off the RGB light. 


Materials List

 

HARDWARE LIST
1 UNIHIKER K10
1 USB Cable

Preparations


Hardware


Connect the UNIHIKER K10 to the computer using a USB Cable.

 

Software


Open Mind+, switch to“Upload Mode”, connect the UNIHIKER K10 as shown in the figure below, and load the UNIHIKER K10 library.

 

Hands-on Practice


Next, we'll use buttons to control RGB light and create an interactive light show.
Task 1: Control of RGB Light On/Off
In this task, we'll use Button A to control RGB light to turn on in three colors, and then use the A+B buttons together to turn off the RGB light.
Task 2: Create an Interactive RGB Light Show
In this task, we'll use Button B to control the RGB light to randomly light up in different colors, creating an interactive RGB light show.


Task 1: Control of RGB Light On/Off


Code 


There are three RGB LED lights on the back lower part of the UNIHIKER K10. Use serial numbers to specify the RGB LED light to control. The correspondence between serial numbers and RGB LED light positions is shown below.

To control the turning on and off of the RGB light, we'll use the "turn on led (0) color (blue)" and "turn off led (ALL)" blocks under the "LED" of the UNIHIKER K10 , as shown in the figure below:

At the same time, we can adjust the light intensity. To do this, we can use "set led brightness (9)" block under the "LED" of the UNIHIKER K10, as shown below:

To control the light with buttons, we also need to use "when button (A) (pressed)" block , which is located under the "Sensors" of the UNIHIKER K10 .
The complete code is shown below:

Note: After setting the brightness, you need to call the display block again to make the set brightness take effect.


Run the Code


Click the“Upload”button, wait for the upload to complete, then press Button A and the A+B buttons respectively to observe the on and off status of the RGB light.

Code Review


 

Category

Blocks

Function

Control the RGB LEDs of the specified LED number to display the specified color.
Turn off the RGB LEDs of the specified LED number.
Set the brightness of the RGB LEDs, you can choose the brightness from 0-9, a total of 10 steps, where 0 is the off state.


Task 2: Create an Interactive RGB Light Show


Code


The RGB light can display a variety of different colors mainly by utilizing the principle of color rendering through the combination of the three primary colors of light. To achieve this, we need to use the function "red(255)green(255)blue (255)"block under "LED" of UNIHIKER K10, as shown below:

Note: The principle of color rendering with the three primary colors for the RGB light can be found in the Knowledge Base.
At the same time, to display colors randomly, we'll use "pick random (1) to (10)" block, which is located in Operators. To create dynamic light show after Button B is pressed, we'll use "repeat until ()" block, which is located in Control.
The complete code is shown below:

Run the Code


Click the“Upload”button, wait for the upload to complete, then press Button B. The RGB light will flash different colors randomly, creating a RGB light show.


Code Review


 

Category

Blocks

Function

Use the principle of mixing the three primary colors of light (red, green and blue) to set the color of the RGB LED lights.


Knowledge Base


Next, let's learn and summarize the hardware knowledge used in this lesson.


The principle of RGB color mixing


1.RGB lights


An RGB light is a type of LED light. RGB stands for the initials of Red, Green, and Blue, which represent the three primary colors. The internal structure of an RGB light is shown below. Each lamp contains one small bead for red, one for green, and one for blue.

 

2.The principle of RGB color mixing


An RGB light combines three single - color LED lights into one bead, which can be seen as three independent lights. When the three internal small beads work at different brightness, it's like mixing the three colors in different proportions, and the final color is the mixed light color, as shown below.

To set an RGB light to display different colors, you can use the blocks about color set of RGB light to select a color. These blocks encapsulate the RGB values of commonly used colors into corresponding color presets for easy use.

However, the number of colors an RGB light can display is far greater than those included in this block. Therefore, by using this block, all colors with values ranging from 0 to 255 can be generated, totaling 16,777,216 colors (256×256×256).
Both blocks are based on the principle of the three primary colors of RGB. Students who are interested can try it out. By using the red, green and blue commands, you can set different values to switch colors.


Introduction to the On-Board Actuators of UNIHIKER K10


1.Concept of Actuators


An actuator is a "practical component" of the UNIHIKER K10. It receives instructions, converts them into visible or audible actions, and can complete tasks independently without extra equipment.
Compared with previously learned sensors, actuators are the "hands and feet" of the UNIHIKER K10. They don't collect information but only "perform actions" and carry out specific tasks after receiving core instructions. In contrast, sensors are its "eyes and ears", only responsible for collecting information and sending it to the UNIHIKER K10's core. 
2.On-Board Actuators of UNIHIKER K10
(1)Speaker: It supports playing simple notes, speech synthesis, recording playback and music playback. Its core function is to "produce sound".
(2)RGB Lights: They are side-emitting type, can output different-colored light effects, and their core function is to perform "light-emitting display". 
(3)Status Indicator: It lights up automatically during operations like voice wake-up, photo taking and recording, and intuitively shows the device's current working status. Its core function is to perform "status indication lighting". 
(4)Screen: It is a visual output component that can display various contents clearly. Its core function is to perform the "content display" action.

The use of the above actuators corresponds to the following blocks:
 

The screen corresponds to the blocks in the "Screen" under the UNIHIKER K10.The status indicator lights up automatically during operations such as voice wake-up, photo taking and recording.


Challenge Task


The Campus Science and Technology Culture Festival requires an interactive lighting device. It should achieve diverse lighting effects via buttons, presenting orderly color cycles and triggering dynamic random color changes. Combine what you've learned in this class to adjust the code of Task 2 and complete the design of this festival light show. 
Tip: Adjust the callback function corresponding to Button A to achieve an orderly color cycle.
The reference code is as follows:

 

icon Project 15.zip 9KB Download(0)
License
All Rights
Reserved
licensBg
0