Lesson 2.2 - RGB LED Variable Brightness Control Scan QR code for Lesson 2.
2 Simulation
Simulation of this lesson can be found at [Link]
Note: (Robot construction must be completed before this Step)
Goal for this lesson
Learn to control RGB LED’s using a repeat cycle and have the LED vary intensity.
Hardware Required
PC or Tablet
1 x micro USB cable
1 x Smart Robot with micro:bit & battery installed
Step 1 As per Figure 1 Figure 1
a. Goto URL [Link]
b. Create “+New Project” & give it a name
c. Press Gear symbol – top right
d. Press Extensions
e. Add repository found using link below.
[Link]
f. On start up both “on start” & “forever” will be in your
work space, move “forever” block below “on start” block.
Step 2 As per Figure 2
a. Press “Loops” Tab
b. Drag “repeat 4 times” into “forever” field.
c. Adjust variable “repeat 4 times” to 51.
Figure 2
Step 3 As per Figure 3
a. Press “K_Bit” Tab
b. Drag “LED brightness 0” into the “on start” field
Adjust brightness to “200”
c. Drag “set RGBled R: 0 G: 0 B: 0” in to “repeat 51 times” field.
d. Press “Basic” Tab
e. Drag “pause (ms) 100” into “forever” field below
“set RGBled R: 0 G: 0 B: 0”
f. Press “Variables” Tab
g. Press “Make a Variable” and type “ledb”
h. Repeat as above for “ledg” & “ledr”
i. Drag “ledr” into R:0 position on “set RGBled R: 0 G: 0 B: 0”
j. Drag “change ledb by 1”
Adjust ledb for appropriate LED colour, in this case use ledr
ledr = Red, ledg = Green, ledb = Blue
Adjust “change ledr by 1” to 5 Figure 3
Step 4
a. Repeat Step 2 & Step 3 for each LED set figure.
This time Adjust “change ledr by 1” to -5
This will bring the led back to its original starting point.
Step 5
a. Repeat Step 2 through to Step 4 for Green & Blue LED’s.
b. Download the code to the micro:bit.
Example RGB LEDExperiment 2.2 can be found at
[Link]
STEM Smart Robot can be purchase from Altronics.
[Link]