Controlling two LEDs with one digital output
simulate this circuit &ndash; Schematic created using CircuitLab

Figure 1. High-side driver and inverter.

How it works:


If GPIO is low then Q1 is off and Q2 is off. Q3's base will find a path to ground through R1 and D1 and will turn on lighting D2.
If GPIO is high then Q1 is on, Q2 is on and D1 will light. Since the collector of Q2 is pulled high Q3's base current will fall to zero and D2 will turn off.
By using PWM (pulse width modulation) the light can blend from one colour to the other.


Does it have to be so complicated?



Figure 2. High-side driver fail.

Yes. Without the NPN transistor of Figure 1 there are two problems:


There is a sneak path for the current through the protection diodes of the micro's GPIO. Whether the output is pulled high or tri-stated to try to shut off the PNP transistor of Figure 2 the base can turn on via D1.
The high voltage - 24 V in your case - may damage the GPIO.




Opto-isolator option:



Figure 3. A pair of opto-isolators simplifies the task further and can isolate the 24 V circuit completely from the micro.


When the GPIO is low the upper opto-isolatore will be turned on.
When the GPIO is high the lower one will be turned on.




The very simple option:

The LED series resistors are clearly visible heat-shrunk in leads of the lamp. If you are prepared to replace these the circuit becomes trivial.



Figure 5. Direct drive of the LEDs.

Setting R1 and R2 to 56 Ω should be fine.

If the output is tri-stated (wired as an input or disconnected by program control) a current will flow through R1, L1, R2, L2 and both LEDs will glow dimly. On a 3.3 V device the voltage wouldn’t be high enough to illuminate both LEDs significantly so they would appear dark.