I have put 11 serial to parallel shift registers(74HC595) in series, daisy chained, hooked up to an arduino uno, the wiring seems to be working okay. I have code which I will provide below that uses an unsigned int leds and has a for loop that makes variable "i" increment up to 32 and sets leds to location i. this loop causes one LED out of 32 to light up at one time. here is the complete code. I did not write this btw, it was from a youtuber by the name of Ricardo Moreno, however I have been trying to wrap my head around how it works.
// Shift Register 74HC595 with 32 LEDs
// Four back to back shift registers
// Global Constants
const int tDelay = 20; // delay between LED switching
const int dataPin = 12; // DS - data serial
const int latchPin = 11; // ST_CP - storage register, latch clock pin
const int clockPin = 9; // SH_CP - shift register clock pin
//Global Variables
bool DirectionState = 0;
/* ***************************************************
* Functions *
*************************************************** */
void updateShiftRegister(unsigned long leds, bool isMSBFIRST = true){
/* Performs all the necessary work to serial load
* two shift registers. Direction controlled by
* isMSBFIRST
* Paramters:
* leds - insigned 16-bit number {required}
* isMSBFISRT - boolean for direction
* true = MSBFIRST
* false = LSBFIRST
* called by void loop */
/* Local variables */
unsigned int leds16 = int(leds);
unsigned int leds32 = int(leds>>16);
/* example: Higher byte Lower byte
* 16-bit word = 00000000 00000000 */
byte low16LED = lowByte(leds16); // extacts the lower byte, right most byte, from a 16-bit word or unsigned integer
byte high16LED = highByte(leds16); // extracts the higher byte, left most byte, from a 16-bit word or unsigned integer
byte low32LED = lowByte(leds32);
byte high32LED = highByte(leds32);
digitalWrite(latchPin, LOW);
if (isMSBFIRST == false) {
// LEDs move from right to left
shiftOut(dataPin, clockPin, LSBFIRST, low16LED); // shiftout only works with a byte value
shiftOut(dataPin, clockPin, LSBFIRST, high16LED);
shiftOut(dataPin, clockPin, LSBFIRST, low32LED); // shiftout only works with a byte value
shiftOut(dataPin, clockPin, LSBFIRST, high32LED);
} else {
// LEDs move from left to right
shiftOut(dataPin, clockPin, MSBFIRST, high32LED);
shiftOut(dataPin, clockPin, MSBFIRST, low32LED);
shiftOut(dataPin, clockPin, MSBFIRST, high16LED);
shiftOut(dataPin, clockPin, MSBFIRST, low16LED);
}
digitalWrite(latchPin, HIGH);
}
/* ***************************************************
* Void Setup *
*************************************************** */
void setup(){
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
/* ***************************************************
* Void Loop *
*************************************************** */
void loop(){
unsigned long leds = 0B11111111111111111111111111111111;
updateShiftRegister(leds);
delay(tDelay);
leds = 0B00000000000000000000000000000000;
updateShiftRegister(leds);
delay(tDelay);
leds = 0B11111111111111111111111111111111;
updateShiftRegister(leds);
delay(tDelay);
for (int i = 0; i < 32; i++){
// set the bit i to 1, starting with bit 0, the least significant bit (rightmost bit)
leds = 0B00000000000000000000000000000000;
bitSet(leds, i);
updateShiftRegister(leds, DirectionState);
delay(tDelay);
}
DirectionState = !DirectionState;
}
I have temporarily uploaded a short 10 second clip to youtube demonstrating how the LEDs are lighting up because the LEDs are a representation of which byte is being sent throught the registers, the lit LEDs are the only bits high in that byte please watch the video first.
There are 88 LEDs in total what I would like to do is have only one of these LEDs on as it goes along all 88 LEDs before the DirectionState changes each time. Since the arduino can only handle 32 bits I am unsure of how to do this, in the video the 3 LEDs that are on are always 32 away from each other because arduino can only send out a 32 bit value max and then it loops and does it again.
I have heard you can chain more than 4 serial to parallel shift registers by using another output for the next chain of 4, id like to be able to send one signal that can light up various LEDs accross all 11 registers in one move if that make sense, rather than having them all 32 LEDs apart looping the same thing. I am aware that the current draw needs to be considered, however I will only ever have to have ~10 at most on at one time. I am also unsure of why all of the LEDs flash on and off, my guess is that it is resetting right before the DirectionState changes, I have also noticed that each 32 LED segment flashes independantly.
I hope I have provided enough information on what I am trying to achieve, I want access to all 11 registers at one time, despite the arduino only working in 32 bit, thank you if you got to this point in my question, and I will respond quickly to any replies, if anymore information is required please let me know, and thank you very much for reading.