In this section, we will learn how to use Pulse-Width Modulation (PWM) together with an RGB LED to create different colors. As a reminder, PWM is a technique to create a variable voltage, which when applied to an LED and resistor pair can be used to change the brightness of an LED. We first discussed PWM and used it to change the brightness of an LED back in Chapter 2, Getting Started with Python and IoT. We then covered PWM in greater depth in Chapter 5, Connecting your Raspberry Pi to the Physical World.
An RGB LED is three single-color LEDs (red, green, and blue) in a single package, as illustrated in Figure 8.1:
Figure 8.1 – RGB LED varieties
You will notice that two types are shown:
- Common Cathode: The red, green, and blue LEDs share a common cathode leg, meaning that the common leg is what connects to the negative or ground voltage source—cathode = negative.
- Common Anode: The red, green, and blue LEDs share...