Dual Color LED =============== .. image:: Images/dualled.jpg :align: center A dual color LED is composed of two LEDs each emitting a different color of light. Two types of dual color LEDs can be found: common anode and common cathode. As a reminder on LEDs, to turn a normal LED on, the anode (longer leg) is linked to the VCC and the cathode (shorter leg) is linked to the ground. In the case of a dual color LED, the internal LEDs share their anode or cathode through one pin: the middle pin. So the wiring depends on whether it’s a common anode or common cathode. Below are the internal connections of a common anode and of a common cathode dual color LED to understand better the placement of the colored LEDs: **Common Cathode**: .. image:: Images/common-cathode.jpg :align: center **Common Anode**: .. image:: Images/common-anode.jpg :align: center *In this example, we will be using a common anode composed of a green and a red LED.* Circuit Connection ------------------ As we mentioned previously, this is a common anode dual color LED. So to light both the green and the red internal LEDs, connect: 1. The middle pin to 3.3V 2. The right and left pin to a ground .. image:: Circuits/dualled-on.jpg :align: center However in this example, we want to control the intensity and the color of our LED, so connect: 1. The middle pin to 3.3V (pin 1) 2. The right pin to a GPIO (pin 11) 3. The left pin to a GPIO (pin 12) .. image:: Circuits/dualled-pwm.jpg :align: center Python program to change the color of the LED --------------------------------------------- .. literalinclude:: Code/dualled.py :linenos: :language: python After saving the code, you can run it by clicking on Run (or CTRL+F5). You will then see the LED transition between multiple stages. Here are three stages of the LED: i=0 - Internal red LED on .. image:: Images/dualled-0.jpg :align: center :width: 60% i=50 - Internal red and green LEDs equally on .. image:: Images/dualled-50.jpg :align: center :width: 60% i=100 - Internal green LED on .. image:: Images/dualled-100.jpg :align: center :width: 60%