Introduction: Micro:bit Experiment 05: RGB LED —— Elecfreaks Mirco: Bit Starter Kit Course

Picture of Micro:bit Experiment 05: RGB LED —— Elecfreaks Mirco: Bit Starter Kit Course

RGB LED is a kind of LED. It can emit light with three different colors: red, green, blue. In this experiment, we are trying to make RGB LED gradually shift its light among the three different colors.

Step 1: Component List

Hardware:

1 x Micro:bit Board

1 x Micro-B USB Cable

1 x Microbit Breadboard Adapter

1 x Transparent Breadboard - 83 * 55 mm

1 x RGB LED

3 x 100 Ohm Resistors

1 x Breadborad jumper wire 65pcs pack

Tips: If you want to buy all components above, you may need Elecfreaks Micro:bit Starter Kit.

Software:

Microsoft Makecode Online Editor

Step 2: Major Component Introduction

RGB LED

RGB LED is a kind of LED, which has integrated red LED, green LED, and blue LED into a component. We all knows that the three primary colors of light are red, green, and blue. With different groups of the three color lights, we can create all colors of the world. Similarly, if we use RGB LED to group lights with different brightness, then it can form various colors.

RGB LED can be divided into 2 types: common anode and common cathode. In common-cathode RGB LED, its common port usually connects GND, while in common-anode RGB LED, its common port connects VCC. In this experiment, we choose common-cathode RGB LED .

Step 3: Hardware Connection

Please complete hardware connection according to the picture below.

After connection, you can see:

Step 4: Programming

Open Microsoft Makecode, write code in edit area. I would like to suggest you program by yourself first.

Of course, if you want to see the whole program directly, you can click the link below. Just click "Edit"on the right top corner of the interface you opened, then click "Download" on the right bottom to download code into micro:bit directly.

Step 5: Code Explanation

Change Value

Set the value for local and global variables. change r by 1 equals "r=r+1".

repeat

Run part of the program the number of times you say.

function

A function is some amount of code you can reuse in your program. You create a function using a function definition which names the function and has its code. A function call is when you use a function by its name somewhere in your program.

call function

Use a function by its name somewhere in a program.

In this experiment, we have set three variables: rgb, which is used to record brightness value of red light, green light, and blue light separately. At the initial status, only red light will be illuminated.

Then we have to create 3 functions to realize gradual change among the three colors.

For example, "RtoG" function is for realizing transformation of red light and green light. If we implement the circulation of the function for once, then P0 analog input "-1"( red light brightness decreased a little bit)

, and P1 analog input "+1" ( green light brightness increased a little bit). After implement circulation for 1023 times, P0 analog input become "0" (red light turned off), and P1 analog input becomes "1023"(green light illuminated). Finally, it has realized gradual change smoothly.

Circulate the three functions to realize color gradual change smoothly.

Step 6: Experiment Result

RGB LED light will shift among the three colors: red, green, and blue smoothly in balance.

1

Step 7: Question:

If we want to use RGB LED to emit cyan light, magenta light, yellow light, then how to design circuit and program? We look forward to your comments or further discussions with us.


Step 8: Relative Readings:

Comments

About This Instructable

88views

2favorites

License:

Bio: ElecFreaks is an open design house founded in March 2011. Our goal is to create rapid prototypes and give small-batch manufacture solution for makers and ... More »
More by ElecFreaks:Use HC-06 Bluetooth Module to Realize Micro:bit Communication With Mobile PhoneInteresting Programming Guidance for Designer--Program Process Control--Condition Statement (Part One)Create an Electro-Theremin
Add instructable to: