5. case 03 RGB led#

5.1. Introduction#

The RGB LED is a kind of LED which creates light of red, green and blue. In this case, we will let RGB LED flash in red, green and blue.

5.3. Hardware Connect#

../../_images/Gca57tq.png

Connect circuit as above picture and put 2 AAA batteries to batteries pack.

5.4. Principles of Circuits#

../../_images/wnBLHqP.png

The GND of slot on micro:bit is into innards of batteries’ GND to generate current loop.

5.5. Introduction of Components#

RGB LED#

The RGB LED is an LED that has 3 integrated LEDs red, green and blue in a single component which is divided into R, G and B channel. It is a wellknown fact that red, green and blue are three primary colors of light. It can mix all color for everything. RGB LED can generate limitless types of color as well. There are 2 types of RGB LEDs, common anode and common cathode. In commoncathode RGB LEDs, the common port connects to GND. While in commonanode RGB LEDs, the common port connects to VCC. Our Experiment Box uses a commoncathode RGB LED.

../../_images/KF4IVxu.jpg

Note: Please note the positive and the negative when you are connecting.

5.6. Software#

Step 1#

Click makecode https://makecode.microbit.org/#

Click on “New Project” and set a new Project.

../../_images/t34k5Zb.png

Step 2#

Snap digital write pin into on button A pressed as below picture. Write 1 to the P0 port, 0 to the P1 port and 0 to the P2 port. It means write 1 to R channel of the RGB and write 0 to G & b channel of the RGB. RGB LED is the red light.

../../_images/sB2lvoi.png

Write code for the green light and the blue light in the same way.

../../_images/Rl1jlrI.png

../../_images/JsaMcnR.png

Program#

Program link:https://makecode.microbit.org/_bm1g8RaVuPkb

You also could directly download program by visiting website as below:

5.7. Result#

When the button A be pressed, RGB LED emits red light. When the button B be pressed, RGB LED emits green light. When the button C be pressed, RGB LED emits blue light.

5.8. Think#

What is the color be after mix of red and blue? Show it!

5.9. Questions#

5.10. More Information#