I am still starting out with arduino and I'm trying to pick up the programming language. I have made a 3x3 matrix and using the digitalWrite() function, I was able to program some simple animations. Anyway, I would like to make an 8x8 led matrix using shift registers to control the leds. I would like to use shift registers because it seems like the easiest way to get more outputs using less pins. I did see a video on youtube that showed a way to multiplex an 8x8 matrix that only used 12 pins, but it used more transistors, resistors, wires, and soldering than I would like to do.
After watching this video on youtube; How Shift Registers Work! - YouTube I am fairly certain I have an understanding for how the shift registers physically work, but the programming part is still questionable. I have scoured the internet for a good tutorial and I haven't really found any that are clear, I really only found the a tutorial, to light up 8 leds in a pattern, many many times, so I decided to give it a go.
I have set up the circuit with only one shift register from this page; http://arduino.cc/en/tutorial/ShiftOut and I got some sample code, I believe from the adafruit tutorials, and modified it slightly to fit my set up. This is what the code looks like;
int latchPin = 8;
int dataPin = 11;
int clockPin = 12;
byte leds = 0;
void setup(){
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop(){
leds = 0;
updateShiftRegister();
delay(500);
for (int i = 0; i < 8; i++)
{
bitSet(leds, i);
updateShiftRegister();
delay(500);
}
}
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, leds);
digitalWrite(latchPin, HIGH);
}
This just makes the leds light up one by one until they are all on, then turns them all off and repeats. I have two questions about this code; for i it goes from 0 to 8, I'm assuming this is for the 8 outputs there are coming from the shift register. However I have seen other codes using shift registers that have this same set up, and the value goes from 0 to 255 so I'm not really sure what this means/does. My other question is that in this code they have "byte leds = 0" this is the only code with shift registers that I've seen that uses this byte function in their code, and I don't know why this is so.
Also, my other concerns are that this is the only way I can program the leds. I would like to program them to light up in a sequence that I can customize, but I'm not sure how to do this. So, is this code similar to the way I would set up my code to light up any led I want? Or is the code set up in a totally different way? And my understanding is that to make an 8x8 matrix, I would need 2 shift registers, one for the cathodes and one for the anodes, and activate them corresponding to which led I want to light up, is this correct?
I apologize for this being so lengthy, but thanks in advance!