Use 2 pins to power LED?

This is best done with 2 current limiting resistors, 1 connected to each pin.

If you simply wire the pins together, you're risking stress or even damage to the hardware if you ever get into a situation where both are output but one drives high while the other drives low. There are a couple ways to avoid that situation, but remember even if you do it perfectly the risk exists for all future code updates so make sure you document it in a way whoever works on the project in the future will know.
 
Using 2 separate digitalwrite(port,val), they will not be executed at the exact same time. And could be separated by any interrupt.
So you will have one line high and one low.
 
When changing two (or more) pins tied together, first use "pinMode()" to change the mode of the pin(s) not being changed. Use "INPUT_PULLUP" if changing the pins to HIGH, and "INPUT_PULLDOWN" if changing the pins to LOW.
Once all but one pin is in the in the appropriate INPUT state, change the desired pin with digitalWrite() or digitalWriteFast(). Then go back and change the other pin(s) one at a time, first using "pinMode()" to set it to "OUTPUT" then using digitalWrite() or digitalWriteFast(). Don't have any other code between a pinMode() call and a digitalWrite() call.

Code:
// Set pins high
pinMode(P1, INPUT_PULLUP);
pinMode(P2, INPUT_PULLUP);
pinMode(P3, INPUT_PULLUP);
pinMode(P1, OUTPUT);
digitalWriteFast(P1, HIGH);
pinMode(P2, OUTPUT);
digitalWriteFast(P2, HIGH);
pinMode(P3, OUTPUT);
digitalWriteFast(P3, HIGH);

// Set pins Low
pinMode(P1, INPUT_PULLDOWN);
pinMode(P2, INPUT_PULLDOWN);
pinMode(P3, INPUT_PULLDOWN);
pinMode(P1, OUTPUT);
digitalWriteFast(P1, LOW);
pinMode(P2, OUTPUT);
digitalWriteFast(P2, LOW);
pinMode(P3, OUTPUT);
digitalWriteFast(P3, LOW);

This avoids the stresses to the hardware, but must be carefully documented so future developers don't change the code.
 
OK, it works, but 🤢
If you need more current than a pin is able to source/sink, just insert a NPN or mosfet transistor.
 
Thanks for the help. This will be a temporary test setup until I can get hold of some transistors.
Dundakitty's digitalWriteFast solution is neat. I may use that for other LED's.
 
Is the problem that if one pin is 'on' and the second pin is 'off', damage can be done to the 'off' pin through reverse current flow?
If I have two resistors, each one needs to be 180 ohms, (3.3v - 1.5V)/.01A. If one pin is turned on and the other is still off, the maximum current that can flow from the one pin through the LED is 10mA. If the 'off' pin was grounded, the maximum current flow to that pin would be 3.3/360 = 9mA.
 
How many "double pin" leds will you have ??? All this current will flow through the chip, maybe reaching the max power or max current on the Vcc (3.3V) pins.
As it is temporary, waiting for the transistors, use only one pin, with a higher resistor to lower the current.
 
My solution for the single LED is:
Pin1 connected via resistor to LED, turns on first, turns off second
Pin2 connected via resistor and diode to LED, turns on second, turns off first.
This prevents each pin from being overloaded, and Pin2 seeing reverse current.
 
But then Pin2 won't be doing anything since the diode will be reversed-biased when Pin1 is turned on. You're going to damage the Teensy by pulling too much current from one pin. Please just use a transistor or a buffer IC.
 
Taking the problem from another side: change led. Chose one which is more brighter at the same current, and use only a single pin, even without transistor.
 
I have to disagree, sort of. I did a test using a power supply to provide 3.3V and set up the arrangement of LED, resistors and diode. I derived the current by measuring the voltage drop across the resistors. With power applied to 'Pin1' resistor only, the current was measured to be 7.5mA. With power applied to both 'pins, the Pin1 current was 7mA and the Pin2 current also 7ma. Not the 20mA total I was aiming for but the closest I could get with standard resistors and not exceed the 10mA limit.
 
Back
Top