Please enter the email address you used on Kickstarter:


MicroView Learning Kit

03 RGB LED

Introduction

You know what’s even more fun than a blinking LED? Changing colors with one LED. RGB, or red-green-blue, LEDs have three different color-emitting diodes that can be combined to create all sorts of colors. In this circuit, you’ll learn how to use an RGB LED to create unique color combinations. Depending on how bright each diode is, nearly any color is possible!

Parts

Component Reference Image
RGB LED RGB LED Diagram
330Ω Resistor 330Ω Resistor Diagram
330Ω Resistor 330Ω Resistor Diagram
330Ω Resistor 330Ω Resistor Diagram
Red Jumper Red Jumper Diagram
Green Jumper Green Jumper Diagram
Blue Jumper Blue Jumper Diagram
Black Jumper Black Jumper Diagram
Black Jumper Black Jumper Diagram

Checkout our breadboard guide and MicroView Pinout for more information.

Breadboard Setup

MicroView Arduino Code

What you should see

You should see your RGB LED go through a colorful sequence of various colors with the slider widget showing the value of each color channel's brightness.

Code to Note

A for() loop is used to step a number across a range, and repeatedly runs code within the brackets {} until a condition is met. We use for loops to change over time the intensity of our RGB pin's brightness. The variable "i" starts a 0, ends at 255, and increases by the amount of the variable fadeStep.

for (i=0;i<=255;i+=fadeStep) 
{}

The MicroView is very very fast, capable of running thousands of lines of code each second. To slow it down so that we can see what it's doing, we'll often insert delays into the code. delay() counts in milliseconds; there are 1000 ms in one second.

delay(dly);

Troubleshooting

LED Remains Dark or Shows Incorrect Color

With the four pins of the LED so close together, it’s sometimes easy to misplace one. Double check each pin is where it should be.

Seeing Red

The red diode within the RGB LED may be a bit brighter than the other two. To make your colors more balanced, use a higher Ohm resistor. Or adjust in code.

analogWrite(RED,i);

to

analogWrite(RED,i/3);

Still No Success?

A broken circuit is no fun, send us an e-mail and we will get back to you as soon as we can: help@geekammo.com

The shocking truth behind analogWrite():

We've seen that the Arduino can read analog voltages (voltages between 0 and 5 volts) using the analogRead() function. Is there a way for the MicroView to output analog voltages as well?

The answer is no... and yes. The MicroView does not have a true analog voltage output. But, because the MicroView is so fast, it can fake it using something called PWM ("Pulse-Width Modulation").

Pins named 3, 5, and 6 within the Arduino code, map to the MicoView physical pins of 12, 13, and 14. Each of these pins are PWM/analogWrite out compatible.

PWM varies the amount of time that a blinking pin spends HIGH vs. the time it spends LOW. If the pin spends most of its time HIGH, a LED connected to that pin will appear bright. If it spends most of its time LOW, the LED will look dim. Because the pin is blinking much faster than your eye can detect, the MicroView creates the illusion of a "true" analog output.

Continue on to circuit 04 Push Buttons