6. case 06 Rainbow LED#

6.1. Our Goal#


  • Use LEDs on robit to make dazzling colorful light.

6.2. Material Needed#


  • 1 x Robit

  • 1 x Mbot Car

6.3. Background Knowledge#


Rainbow LED#

RGB color model is a color standard in the industry. It can be used to create a variety of colors through the change of RGB channels and their interactive mixture. RGB stands for red, green and blue. This standard has almost included all kinds of colors that are visually perspective by human eyes. It is one of the most widely used color system.

Rainbow LED is a kind of LED. It has integrated red, green and blue LED into one component. We all know that the three primary colors of light are red, green and blue. With different color combination, we can synthesize the color of all things. Similarly, by combining different RGB brightness of light, we can also create an infinite number of colors.

The LEDs on Robit are WS2812b LEDs, which have similar outlook with 5050 bead. Each bead is a pixel. The picture below is a single bead that has four pins.

../../_images/um2QZl8.png

6.4. Hardware Connection#


Two rainbow LEDs onboard are connected to P12 on micro:bit.

../../_images/yOJCtFk.png

../../_images/VB66oQ7.jpg

6.5. Software#


Microsoft Makecode

6.6. Programming#


Step 1#

Click Advanced in the code drawer of MakeCode to see more code options.

../../_images/LjMR5IU2.png

To program for robit, we have to add a package. Find Add Package in the bottom of code drawer and click it. This will pop up a dialogue box. Search Robit and then click to download this package.

../../_images/ISZ6w261.png

Note: If you get a hint that some packages will be deleted due to the problem of incompatibility, you can either follow the prompts, or create a new project in the project menu.

Step 2#

When start, we have to create a variable item to assign values to LEDs. Let’s define its initial color to be 0.

Then create a forever loop and make variable item increase by 5 during each circulation. If the value of item equals to 360, then set it to be 0 to restart loop.

../../_images/UG17sXN.png

Note: Picture below is the detailed code explain of LED.

../../_images/fojUByb.png

6.7. Program#


You can see the whole program from the link here: https://makecode.microbit.org/_DLqKtp38EVro

Or you can download it from the page below.

6.8. Result#


We can see the color of LED light is changing circularly.

../../_images/9KOWt1T.gif

6.9. Think#


How to make the color change swiftly instead of smooth change?

6.10. FAQ#


Q: How to change RGB flash speed?

A: Renew the change rate of the variable item.