This time I'll use a Digilent Nexys2 Board (with spartan3e 1200k FPGA) in which there is a Leon3 IPCore with GRGPIO controller to drive the expansion port. Nothing forbids you to use Arduino Board: in fact you need only 9 pins in this configuration.
For convenience I'll use a software driver very similar to Arduino (i.e. pinMode, digitalWrite, etc.) plus some useful function that accept mask as parameter (i.e. pinModeMask, digitalWriteMask, etc.): in this way in the "same cycle" it's possible to change the mode or the logical value to some pins. In any case it would be easy to implement a function that accepts input masks on Arduino. Maybe I'll do in next article =P.
How you can use only 9 pins to drive 20 LED? It's very easy, of course! You have to build a LED matrix and link cathodes along the rows (columns) and anodes along the columns (rows); in this way you cannot drive all LEDs in the same time. But our eyes are (very) slow and we have to exploit this feature.
In my case I'll connect the 4x5 LEDs in this way: the 5 rows connect the cathodes (5 cathodes), the 4 columns connect the anodes (4 anodes).
You can power up each anode in a loop (powering down the others) and configure the cathodes to light the LEDs you want (this is because the anode is less than the cathode: in this way every cycle has a shorter duration). If the LED has to be power off you have to change the pinMode of cathode pin to input (in this way the pin sets high-impedance, preventing the current passage) else as output with low value (allowing the current passage). In this way only one row (column) is working, the others are switched off; if the loop frequency is at least 30/40Hz our eyes don't perceive that a line is turned on while the others are off, but they see all LEDs lit at the same time.
So the first thing you have to define 4 pin consecutive what will drive anodes: in every loop highAnode = highAnode + 1 mod 4. In each cycle you have to configure the cathodes too.
Now you have to create a coder that transform ASCII chars into cathodes setting (maybe this requires several minutes and tests). Also, if you want, you can implement a shift mechanism to display some characters. Watch the video below to see a rough draft of the display.
In my case I'll connect the 4x5 LEDs in this way: the 5 rows connect the cathodes (5 cathodes), the 4 columns connect the anodes (4 anodes).
The resistors (100Ω) connect the pins to anodes |
So the first thing you have to define 4 pin consecutive what will drive anodes: in every loop highAnode = highAnode + 1 mod 4. In each cycle you have to configure the cathodes too.
Animation at 1 Hz of explained concept |
Cya!