I was bored this past sunday, and needed something to ease my racing brain β¦ so I picked an easy project with lots of flash.
The parts list:
Eight Tri-Color or RGB leds β¦ each led package contains three LEDs
Three 74HC595 Shift Registers β¦ serial load, latching. other varieties would probably work too.
One Microcontroller β¦ doesnβt matter what it is, I used a pic18f252 since it was handy.
Twenty-Four Resistors β¦ I used 150 ohm to set my led current at 20mA, but use anything from 56-220 ohms
The tri-color leds I used are wired as common anode LEDs β¦ each led inside the package has its own cathode pin and shares a common anode pin. So, all my anode pins connect to the postive rail on the breadboard. Thereβs no reason a person couldnβt use twenty-four discrete LEDs, or eight common cathode leds. Since my leds are βactive lowβ, outputting a 0 turns them on, outputting a 1 turns them offβ¦ if you used common cathode leds, they would be βactive highβ, a 1 would turn them on and a 0 off. If you used discrete leds, well, hook βem all up one way or the other.
Next comes the connections to the shift registers. Think of each register as a chip containing eight switches you can turn on or off remotely. Each of the 24 LEDs gets connected to an output on the register, and they need to be grouped by color and kept in order. So looking at the picture below, working left to right, I connected all the red leds to the first register, all the blue to the second, all the green to the third. This resulted in the rats nest of wires you see between the chips and the leds. Concerning the registers themselves, they have three connections of up-most importance. Pin seven is the ground connection, pin fourteen is the +5v connection, and pin thirteen is the enable or tri-state pin. The tri-state pin must be tied to ground in order for the outputs on the register to work. Next up is the data connections. The 595 offers a nifty feature of serial pass-through. Using this feature, you can chain a bunch of them together, and treat them as a large number (in the programming). This is done with the QH* and SER pins. QH* connects to SER on the next ic βdown streamβ. On the first IC (the rightmost in my picture), SER connects to the microcontroller. Now in order to βloadβ the chips with serial data, the microcontroller has generate a βclockβ for all the chips to sync to. This clock signal is transmitted on the SCK (serial clock) line. All three SCK lines are wired in parallel to the microcontroller. Last, since we want the data to be retained by the registers, even if the pic stops transmitting, we need to latch the data. This is controlled by the last data line, RCK. When the microcontroller is finished transmitting data, it needs to pulse the latch clock RCK high briefly. Upon receiving this signal, the registers display the data which they just received, and continue to display it until told otherwise. I have some other lines connected, but donβt use themβ¦ they are the SCLR line, which clears the data from the buffers, and the enable line. The microcontroller keeps the enable line high (disabling the registers outputs) until it is read to start sending commandsβ¦ this prevents the registers from powering up with weird random data being displayed.
Thatβs it for the hardware side β¦ really simple. All the magic happens in softwareβ¦ which I will write about in part two (yes, Iβll post the code too). As a spoiler, all the software does is boolean math, shifting and inverting 8-bit words of 1β²s and 0β²s around.
The parts in the grayed out areas are just stuff left over on the breadboard from an earlier project, or support components for the microcontroller.
Here are some videos:
Initial Test Program:
UPDATE:
Due to all the connections (24 of them between the registers and the LEDs), drawing a schematic can get messy. I chose to avoid this mess by using Eagle βBUSβ feature, which allows a large number of signals to be combined into one wire. The schematic below is drawn using a much less expensive and smaller PIC than the one pictured in the breadboard β¦ however the idea is still the same.
For more detail: Rainbow LED Chaser