Current sinking and sourcing on the same pin.

Hi! I've been trying current sinking and sourcing from the same pin of arduino and here's what i've got:

  1. pinMode(13, OUTPUT), digitalWrite(13,HIGH), pin to ground - works nicely (current sourcing)
  2. pinmode(13, OUTPUT), digitalWrite(13, LOW), pin to 5v (current sinking). Now why does this work? Firstly i've tried to set the pin to input and then sink current, but nothing happened. It seemd like it was a high impedance there. Can anyone clue me as to what is going on here, and how does digitalWrite and digitalRead work in plain terms please? Thank you so much!

What value resistor are you using? You might have damaged it with your first test...

When pinMode is set to OUTPUT and digitalWrite is used:
There is one transistor that connects the pin to 5V when a HIGH is commanded.
There is a 2nd transistor that connects the pin to Gnd when a LOW is commanded.

When pinMode is set to INPUT:
The output transistors are turned off. The pin connects to the input of a latch, and the High/Low level is latched in when a digitlalRead is commanded.

The uc is fine, i used a resitor. Also CrossRoads's explanation is excelent. So until digitlalRead command is given, the pin is basically disconnected?

I asked this question based on the following decoder example (Check the pic. below, especially pin 0 and 9). I think i’ve got it now ( tell me if I’m wrong with this phrasal verb, I’m not so good at speaking english ).

If the outputs of this decoder are active low this means that it’s main function of it is to sink current, whereas an active high decoder is made to source current, right? Or this things are interchangeable and there is no difference at all?

Thank you again for your time!

Active Low just means that when asserted it goes low, not high. It is a logic function, not an electrical function. It has nothing to do with the amount of current it can sink or source.

74154 has only 1 output Low at a time.

"If the outputs of this decoder are active low this means that it's main function of it is to sink current, whereas an active high decoder is made to source current, right?"
Yes. With logic chips, that is not very much current tho.

For your circuit, only 1 of the 6 NAND gates will have a High output at any one time as only 1 74154 output will be low at any 1 time:
NAND Gate logic:
A B Y
0 0 1
0 1 1
1 0 1
1 1 0
or 1 LED will turn on.

So if all pins are high except for 1, all NAND gate outputs will be low except for 1 when the 2 two enable pins (marked here as E/) are low.
All will be low when E/ is high.

alexmath:
The uc is fine, i used a resitor. Also CrossRoads's explanation is excelent. So until digitlalRead command is given, the pin is basically disconnected?

digitalWrite.

Yes.

No. Until a pinMode function is called, with OUTPUT mode.

Until that, it is disconnected.