Data Sheet

UCTRONICS Ultimate Starter Leaning Kit for Raspberry Pi #K0064
75 www.uctronics.com
8.8 Project 8: Controlling a RGB LED with PWM
8.8.1 Overview
In this lesson, we will program the Raspberry Pi for RGB LED control, and make RGB LED
emits a variety of colors of light.
8.8.2 Requirement
Raspberry Pi ×1
RGB LED ×1
220Ω Resistor ×3
Breadboard ×1
Several Jumper wires
8.8.3 Principle
1. What
s RGB LEDs ?
Please refer to chapter 3.21.1 RGB LED
What we used in this experiment is the common anode RGB LED. The longest pin is the
common anode of three LEDs. The pin is connected to the +5V pin of the Raspberry Pi,
and the three remaining pins are connected to the Raspberry Pi’s D9, D10, D11 pins
through a current limiting resistor.
In this way, we can control the color of RGB LED by 3-channel PWM signal.
2. Key function
int softPwmCreate (int pin, int initialValue, int pwmRange)
This creates a software controlled PWM pin. You can use any GPIO pin and the pin
numbering will be that of the wiringPiSetup() function you used. Use 100 for the pwmRange,
then the value can be anything from 0 (off) to 100 (fully on) for the given pin. The return
value is 0 for success. Anything else and you should check the global errno variable to see
what went wrong.
void softPwmWrite (int pin, int value)
This updates the PWM value on the given pin. The value is checked to be in-range and pins