I am trying to control a LED Ring (consisting of single LEDs ) through a 595 shift register (it will be 15 LEDs through 2 registers but for my testing setup, I am just using 8 LEDs and a single 595).
Everything works fine when testing, however one thing has me very confused. I triple checked the wiring but it seems to either send the bits in a wrong order or my pinout is different. What happens in the following testcode is that the LED connected to output H/7 (0-indexed) on pin 7 displays the LSB.
output A/0 puts out the 2nd LSB
.....
output G/6 puts out the MSB
I can't seem to find any fault in the code itself (tried changing int to byte, MSBFIRST to LSBFIRST to no avail) and I did triple check my wiring. Being new to the physical side of it (working with chips etc) , I wonder if there's any chance that my 595 has an unusual/weird pinout (although that doesn't seem too likely)? Or did I misunderstand in what order the bits are written / the routing or whatever?
Everything works fine when testing, however one thing has me very confused. I triple checked the wiring but it seems to either send the bits in a wrong order or my pinout is different. What happens in the following testcode is that the LED connected to output H/7 (0-indexed) on pin 7 displays the LSB.
output A/0 puts out the 2nd LSB
.....
output G/6 puts out the MSB
Code:
//Pin connected to ST_CP of 74HC595
int latchPin = 7;
//Pin connected to SH_CP of 74HC595
int clockPin = 8;
////Pin connected to DS of 74HC595
int dataPin = 9;
void setup() {
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
// count from 0 to 255 and display the number
// on the LEDs
for (byte numberToDisplay = 1; numberToDisplay < 256 ; numberToDisplay++ ) {
// take the latchPin low so
// the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
char debugmsg[16];
sprintf(debugmsg,"Writing %d\t",numberToDisplay);
Serial.print(debugmsg);
delay(20);
}
}
I can't seem to find any fault in the code itself (tried changing int to byte, MSBFIRST to LSBFIRST to no avail) and I did triple check my wiring. Being new to the physical side of it (working with chips etc) , I wonder if there's any chance that my 595 has an unusual/weird pinout (although that doesn't seem too likely)? Or did I misunderstand in what order the bits are written / the routing or whatever?