

LOWER SECONDARY

COMPUTER SCIENCE

LASERBOX

40MINS
Hardware requirements:
mBot/mCore Control Panel
Implementation:
Upload the program to Arduino
Effect demo
Example programs
Script description
![]() |
Adjust the values (or double click the number area to enter values) and let the onboard LED to mix red, green and blue in a certain ratio. In the example script, the onboard LED lights red, yellow, green, azure, blue, pink and white in order. The value behind red, green and blue are the brightness of each color. The bigger the value is, the brighter the color is (range from 0 to 255). |
![]() |
Control the color changing frequency of the LED lights by setting waiting time. |
![]() |
Repeat the process to make the LED flash. |
Knowledge points
Point 1 Principles of color and light mixing
The color of the onboard LED is three original color mode (RGB color model, or RGB color model or red, green and blue color model). It is a color-adding model, which could show diversified color effects by mixing two or three colors of them in different ratio.
![]() |
It can be known from the left diagram that Red+green=yellow green+blue=azure blue+red=pink red+blue+green=white |
Point 2 Color and light of the onboard LED
For the color and light values of the onboard LED, you can refer to RGB color map (as the bigger the value in is, the brighter the light is, and mixed color is brighter than single color. It is normally to set the value below 40 to prevent dazzling and better identify color and light).
In addition to the color plan in this example program, we can also inquire RGB color table to set the onboard LED color: As the onboard LED can better be identified when the value is below 40, so we can divide the RGB value (the 3rd column in the following table) by 10 and round it to determine the on-board LED value (the 4th column in the following table).
RGB real color |
Name | R.G.B value | Onboard LED value |
Block setting |
Cyan4 | 0 139 139 | 0 14 14 | ![]() |
|
DodgerBlue | 30 144 255 | 3 14 26 | ![]() |
|
SpringGreen2 | 0 238 118 | 0 24 12 | ![]() |
|
Firebrick | 178 34 34 | 18 3 3 | ![]() |
|
VioletRed | 208 32 144 | 21 3 14 | ![]() |
|
Maroon | 176 48 96 | 18 5 10 | ![]() |
|
DarkGoldenrod4 | 139 101 8 | 14 10 1 | ![]() |
Point 3 What if you execute two LED blocks of different color?
As the script runs fast, if there is no “waiting” between “red light” and “blue light”, it is the same with lighting red and blue at the same time, and then you will see yellow. The following two scripts are lighting yellow when they are executed.
Script | Effects (upload the program to Arduino) |
![]() |
The onboard LED continually display yellow |
![]() |
Extended tasks
Use the RGB color table to modify the proportion of red, green and blue light to make beautiful lighting effects. (It is required to upload the program to Arduino.)
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.