I want to sanity check an idea I had before I go and cook pins on my Arduino. Lame ASCII art ahead.
Supposing I had the following:
pin2->LED->resistor->GND
When pin2 is HIGH, the LED lights up. The LED is off when the pin is LOW.
If I do this:
+5V->LED->resistor->pin2
Then when pin 2 is HIGH, the LED is off, and when pin 2 is LOW, the LED is on. This much I have seen elsewhere and tested myself.
Now I get a little crazy. What if I do something like this:
pin2---+LED1--resistor-----pin4
|------resistor--LED2+------|
"+" to indicate the anode of the LED. Bottom circuit connected to the top at the "|".
If I set pin2 HIGH and pin4 LOW, then theoretically, I get a lit LED1 and LED2 is off. If pin2 is LOW and pin4 is HIGH, LED2 should light and LED1 is off. Which means I have reversed polarity.
Time for the first sanity check: Is this a bad idea? Am I going to cook something doing this? How much amperage can I drive this way? Probably not more that the 50mA that the specs say right?
Not to stop with that level of craziness, what if I do something like this:
pin9---+LED1--resistor-----pin4
|------resistor--LED2+------|
Same arrangement, but with pin9 instead of pin2.
Now I can theoretically raise and lower the brightness of LED1 while pin4 is LOW by varying the voltage on pin9 via analogWrite. LED2 will be off of course. And I can do the same with LED2 while pin4 is HIGH (and LED1 would be off).
Does it really work this way? Would this get rid of the need for an H-bridge if I were drawing low enough amperage? How long before I cooked my Arduino?