2 or 3 LED colors on a single digital pin

Simulator links
Is there a problem with the circuit using the Optocoupler posted above?

I think the existence of a voltage divider is unavoidable unless you use something another active component IC like a @LarryD's circuit.