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. Principles of Circuits¶
The GND of slot on micro:bit is into innards of batteries’ GND to generate current loop.
5.4. 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 well-known 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 common-cathode RGB LEDs, the common port connects to GND. While in common-anode RGB LEDs, the common port connects to VCC.
Our Experiment Box uses a common-cathode RGB LED.
Note: Please note the positive and the negative when you are connecting.
5.5. Software¶
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.
Write code for the green light and the blue light in the same way.
Program¶
Program link:https://makecode.microbit.org/_bm1g8RaVuPkb
You also could directly download program by visiting website as below:
5.6. 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.