Driving a bi-colour, 2-pin LED with one pin is possible!
When GPIO1 pins are in short supply a bi-colour 2-pin LED may seem like a good idea.
It can be done, but is not that efficient.
How it works
- When GPIO is low R1 provides current to L2 and the indicator glows red.
- When GPIO is high current flows through L1 and R2 to ground and the indicator glows green.
- By alternating the GPIO high-low fast enough both LEDs can be illuminated giving an orange colour (since they’re both in the same package). By varying the ‘on’ pulse width a smooth cross-fade can be given from red to green.
- If the GPIO is tri-stated (disconnected) the LED will be dark.
Note that this circuit is not very efficient. R1 and R2 pass current to ground always and when the red LED is on R2 is stealing power from it and when the green LED is on R1 is stealing power from it. It may take some experimentation to get this to work.
See also 1 GPIO – 2 LEDs.