Hey Arduino-Community,
I'm pretty new here in the section of arduino's and now i wanted to start my 1st project.
I've got a 8 LED in a row "Matrix" ( http://dl.dropbox.com/u/17103210/IMG_0627.JPG ) with a shift register and there is my problem.
I don't know how i can control a singleor more than one LED with a shift register(i never worked with a shiftig register before) and of course I already read the topic
about "ShiftOut" ( http://www.arduino.cc/en/Tutorial/ShiftOut ), but I didn't find any helpful information which can solve my problem.
I'm grateful about any kinda help :).
Best regards ,
idl0r
Have you read this tutorial - http://www.arduino.cc/en/Tutorial/ShiftOut -
and read this pages about bit math - Arduino Playground - BitMath -
this is the basic knowledge you need for your project.
How to control a shift register:
Connect three wires, data, clock, and latch, from the shift register. If you more than one shift register, connect the clock and latch pins to each one, and the "data out" of one to the "data in" to the other.
Then, to control it, you do a digitalWrite for the value the first output should have on the data wire. Then, digitalWrite the clock pin high and then low again. Repeat for each output on each shift register. Then digitalWrite the latch pin high and then low again. At this point, the outputs should become the values you tell them to.
This can be simplified by using the shiftOut function. To use this, just give it the three pins, the order (MSBFIRST or LSBFIRST, it doesn't matter which you choose, but if your image is backwards, switch them around) and the data you want to send -- in your case, what LEDs you want to light up (use the format "B00111010" to get the first two LEDs off, the next three on, etc)
How to control an LED Matrix:
The basic premise of controlling an LED Matrix that you light the appropriate LEDs for one row and cycle through the rows. Attach all of the rows to one shift register and all of the columns to another. Then, use something like the TimerOne library to call a function every 100 ms. The function should retain a counter of what row it's currently on, then use a lookup table to figure out what column LEDs to turn on.
Here's some example code that is untested.
#include <TimerOne.h>
byte picture[8] = {
B01100110,
B11100111,
B11111111,
B01111110,
B01111110,
B00111100,
B00011000,
B00011000,
}
const int clockPin = 9;
const int dataPin = 10;
const int latchPin = 11;
void setup() {
TimerOne.initialize(1000); //These two lines have the arduino automatically
TimerOne.attachInterrupt(screenUpdate); //call screenUpdate every 1000 microseconds
}
void loop() {
for (int i=0; i < 8; i++) {
picture[i] = ~picture[i]; // Reverse each row
}
delay(500);
}
void screenUpdate() {
static int curRow = 1; // Static means keeps value loop to loop
//~_bv means the inverse bit value of curRow -- basically
//~_bv(1) = B11111110, ~_bv(2) = B11111101, ~_bv(3) = B11111011..
//invert because the rows are generally the negatives of the LEDs
shiftOut(dataPin, clockPin, MSBFIRST, ~_bv(curRow));
//shiftOut the data for the current row.
shiftOut(dataPin, clockPin, MSBFIRST, picture[curRow]);
curRow = (curRow + 1) % 8; //Increase curRow, and loop to 0 if it's 8
}