Introduction
Sparki features an RGB (Red, Green, Blue) LED, which is a light capable of illuminate in nearly any visible color:
What will you need
How It Works
As its name implies, an RGB LED combines (by adding them) the red, green and blue colors to obtain a broad range of visible colors. This is called the
RGB Color Model. You can get an idea about how the colors are combined in an RGB LED looking to the following picture:
Programming Sparki’s RGB LED
Using the Sparki’s RGB LED with miniBloq is easy. There is an specific block to control it, which can be used to create nearly any color:
It receives three (numeric) parameters: the first defines the value of the red component, the second is the value of the green component, and the third is the value of the blue one. Each parameter ranges from
0 to
100, where a value of
0 means complete absence of that color, while
100 means the maximum presence of if. For example, the following one-block program simply lights the LED in pure red:
You can play a bit with the other values there to create different colors. Try for example the following combinations:
Now that we understand the basics beyond the RGB LED, let’s do something that changes with time. The following program will fade in the blue color component, and when it reaches its maximum value (
100), it will restart from zero. As always, you can make changes to the different values used in this program, for example to make things work faster (or slower), or smother:
Now, you can try to modify that program to create different color combinations, by fading the other color components too.
Finally, let’s use a bit of math. The next program uses a
sine trigonometric function to achieve a smoother fading on the blue color component. As the sine (
SIN block in miniBloq) returns a value from -1.0 to +1.0, we need to add an
ABS block there, and also to multiply this result by
100. The
ABS block will convert any value that it receives as a parameter, into a positive number:
As you can see at this point, the RGB LED is a rich hardware device, so we encourage you to experiment with it, finding new light effects and color combinations.