hm.... im confused!
if the 74HC595 is not really meant for driving LEDs what are all the LED shiftOut tutorials for the 74HC595 doing out there?
say
http://www.arduino.cc/en/Tutorial/ShiftOut --- isn't this just plain wrong then? :o
when will it all fry?
i've done a basic 32 LED project, and the 4 shift registers i'm using are acting funny.... so i'm wondering if they might be burned?
my wiring is like:
http://www.arduino.cc/en/Tutorial/ShiftOut -- only with 4 shift registers in stead of 2
and here is my code:
/*
4 shift register, skips one bit??
*/
// setup up shift register
int clockPin = 12;
int latchPin = 8;
int dataPin = 11;
int ledPin = 13;
boolean ledState = HIGH;
long lastUpdate = millis();
long lastShift = millis();
int registers = 4;
// a byte keeps 8 bits, one byte pr shift register
byte data[] = {0,0,0,0};
int count = 0;
void setup() {
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
compileBytes();
blinkAll(1000);
}
void loop()
{
if (millis() > lastShift+500) {
shiftRight();
lastShift = millis();
}
sendData();
}
void shiftRight() {
count = count+1 ;
if (count==8*registers) count = 0; //wrap around
compileBytes();
printStatus();
}
void compileBytes () {
//blink LED
ledState = !ledState;
digitalWrite (ledPin, ledState);
//compile bytes
for (int i = 0;i<registers; i++) {
for (int j = 0; j<8; j++) {
if (count == i*8+j) {
bitWrite(data[i], j, HIGH);
} else {
bitWrite(data[i], j, LOW);
}
}
}
}
void sendData() {
//write data
digitalWrite(latchPin, 0);
for (int i = 0;i<registers; i++) {
shiftOut(dataPin, clockPin, LSBFIRST, data[i]);
}
digitalWrite(latchPin, 1);
}
void printStatus() {
Serial.print("count: ");
Serial.println(count);
for (int i = 0;i<registers; i++) {
for (int j = 0; j<8; j++) {
if (bitRead(data[i], j)) {
Serial.print("1");
} else {
Serial.print("0");
};
}
Serial.print(" ");
}
Serial.println();
}
void blinkAll(int d) {
digitalWrite(latchPin, 0);
for (int i = 0;i<registers; i++) {
shiftOut(dataPin, clockPin, LSBFIRST, 255);
}
digitalWrite(latchPin, 1);
delay(d);
digitalWrite(latchPin, 0);
for (int i = 0;i<registers; i++) {
shiftOut(dataPin, clockPin, LSBFIRST, 0);
}
digitalWrite(latchPin, 1);
delay(d);
}
the sequence they go through is like this:
blinkAll():
all on: 11111110
all off: 00000000
loop():
1: 00000010
2: 00000100
3: 00001000
4: 00010000
5: 00100000
6: 01000000
7: 00000000
8: 10000000
--- so the 8th LED nevers lights up (on all 4 shift registers), and in the loop the shift registers basically skip step 1, and adding a blank step on step 7
my code seems to be right. if you turn on the serial monitor, you can see a printout of the 4 bytes sent to the registers... it all seems ok...
what am i doing wrong here?
/j