User Manual

32
Lesson 5 RGB LED
Introduction
Previously we've used the PWM technology to control an LED brighten and dim. In this
lesson, we will use it to control an RGB LED to flash various kinds of colors.
Components
- 1 * Raspberry Pi
- 1 * Breadboard
- 1 * RGB LED
- 3 * Resistor (220Ω)
- Several jumper wires
Principle
RGB
RGB LEDs emit light in various colors. RGB stands for the red, green, and blue color channels
and is an industry color standard. They package three LEDs of red, green, and blue into a
transparent or semitransparent plastic shell and have four pins. An RGB LED can display
various new colors by changing the three channels and superimposing them, which,
according to statistics, can create 16,777,216 different colors.
The three primary colors can be mixed into various colors by brightness. The brightness of
LED can be adjusted with PWM. Raspberry Pi has only one channel for hardware PWM
output, but it needs three channels to control the RGB LED, which means it is difficult to
control the RGB LED with the hardware PWM of Raspberry Pi. Fortunately, the softPwm
library simulates PWM (softPwm) by programming. You only need to include the header file
softPwm.h (for C language users), and then call the API it provides to easily control the RGB
LED by multi-channel PWM output, so as to display all kinds of color.
RGB LEDs can be categorized into common anode and common cathode ones. In this
experiment, the latter is used.