I have a circuit that has 4 LEDs that are controlled by a microcontroller. Only one LED needs to be illuminated at a time. I would like to be able to control the brightness of the LED that is on via pulse-width modulation however I only have one PWM pin available. I do have 4 standard GPIO pins available though. I am wondering the circuit that I have drawn below would work?
I would configure GPIO 1 as an open-drain output and set up the PWM on it to control the brightness. Initially, to turn both LEDs off, I would configure GPIO 2 and 3 as push-pull outputs and drive them high. My thought it that this would put 3.3V on both sides of the LEDs thus preventing current from flowing through them. Then if I wanted to turn on LED1 I would just configure GPIO2 to float.
My guess is that I will have problems with the amount of current that is being sunk into GPIO1 if I did this with 4 LEDs. But I'm not sure?
Would this circuit or something similar work or do I need to add transistors to pull this off? The micro is a PIC24F if that matters.