You want more ports?


When digital electronics started nearly everything had negative logic meaning the devices whatsoever (bulbs, coils, etc.) had to be connected to the output of the electronic circuit and to the positive power supply.

With the microcontrollers the outputs can operate as source or sink.

So a circuit like this is possible if and only if
the sum of the forward voltages of both LEDs exceeds the voltage of the power supply. Only blue and white LEDs do the trick. When you get an LED check the data sheet for the UF value.

So you really have three possible states:

  1. set the pinMode of that port to INPUT: none of the LEDs will shine
  2. set the pinMode to OUTPUT and digitalWrite LOW to that port: the upper LED will shine
  3. set the pinMode to OUTPUT and digitalWrite HIGH to that port: the lower LED will shine
If you switch fast options 2 and 3 you will see both LEDs shining.

If you don't have blue or white LEDs you might take 2 LEDs of any other color to replace one of the blue or white ones.
Just make sure that the sum of the forward voltages of all your LEDs is not less than the supply voltage.

If you still run of ports, check for Charlieplexing.


contact: nji(at)gmx.de