The diagram is very simple : |
|
- There are four LEDs
- and two resistances of 100 ohms.
Price : 5 FF
Or :
- There are two LEDs
- Four diodes 1N4148
- and two resistances of 100 ohms.
Price : 4 FF
|
|
The principle is not much more difficult. |
When the port of the PIC is at 0, the red LED is correctly
polarized, the current crosses it (from 10 to 20 mA). It is lighted on.
If the port is put at 1 (5V), this time the yellow LED is crossed by a current.
Now if you quickly turn the port from 0
to 1 and 1 to 0 (at more 50Hz), you will have the impression
that the two LEDs are lit.
You know now how to light the red LED or the yellow one, individually or
simultaneously (at least seemingly),
- But how to turn them off both ?
- It is very simple ;-)
You just have to turn the port in high impedance, i.e. input.
And the LEDs will not be any more fed and will be thus turned off.
I can now explain you the role of the second
LED in series (or of the 2 diodes): When the port is set as an
input, the wiring is found isolated from the PIC. The 4 LEDs and 2
resistances in series are fed in 5V but this is not sufficient to
light on the LEDs. The threshold of the LEDs being of 1,5V minimum, it would
be necessary at least to have 6V so that a current crosses them (it is the same thing for
the diodes with a threshold of 0,6V minimum, having a power of 5,4 V).
This phenomenon does not occur if the PIC itself feeds the
high or low part of the diagram, in this case the threshold are at 3V (or 2,7V).
By the way ! : When you light the 2 LEDs, the
average power is shared between the two and when you want to light
only one LED, it receives all the power. Therefore to do it properly, in order to
have the LEDs lit with the same intensity and in the case of one single LED lit,
it is necessary swing from a high/low level to a high impedance state (and not as I wrote it before,
I wanted to simplify the description).
Well. Very well. You now just have to write the program ;-)
So I launch the contest of the most optimised function
to light on these LEDs. It's your turn to work !
I will soon give my answer and the most interesting ones that I have received on the
forum.
|