Permalink
Branch: master
Find file Copy path
c843c24 Jul 13, 2018
1 contributor

Users who have contributed to this file

104 lines (54 sloc) 3.35 KB

Our Goal


  • Use LEDs on robit to make dazzling colorful light.

Material Needed


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.

Hardware Connection


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

Software


Microsoft Makecode

Programming


Step 1

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

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.

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.

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

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.

<iframe style="position:absolute;top:0;left:0;width:100%;height:100%;" src="https://makecode.microbit.org/#pub:_DLqKtp38EVro" frameborder="0" sandbox="allow-popups allow-forms allow-scripts allow-same-origin"></iframe>

Result


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

Think


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

FAQ


Q: How to change RGB flash speed?

A: Renew the change rate of the variable item.

Relative Readings