Sending bits to 2 x 74HC595 shift registers

Hi, been reading a lot of topics on this forum and found this subject a little sketchy and over complicated for a beginner like myself.

I just want something simple extend my outputs and turn on more than 8 bits. Without just pushing bits from one register to another, I may wanted to just to turn the bits on the second register.

So I have written this and hopefully it might help some other beginner like myself.

Shift_Register_74HC595.ino (3.66 KB)

It might be more helpful if you post your code.

/* 74HC595 High speed 8-bit register, circuit with 2 x 8-bit registers
// Pinout datasheet https://www.diodes.com/assets/Datasheets/74HC595.pdf
// Wiring diagram, THIS IS NOT MY DESIGN but will work if you change the DS, SH, and ST pins
// Wiring diagram https://www.arduino.cc/en/uploads/Tutorial/ShftOut_Schm2.jpg

// PIN_9 [Q7S] Serial data output - connect to second register of PIN_14
// PIN_10 [MR] Master reset input - connected to 5v rail
// PIN_11 [SHCP] Shift register clock in
// PIN_12 [STCP] Storage register clock in - if you have flicker when the latch pin pulses use 10uf
// PIN_13 [OE] Output enabled input - connected to 0v rail
// PIN_14 [DS] Serial data input
*/

int ds_Input = 4; // Inputs to 74HC595 to shift register
int sh_Input = 2; // connect to arduino output pin 4 to input pin 14
int st_Input = 3; // output pin 2 to input pin 11
// output pin 3 to input pin 12

// ** For conversion use windows calculator programmer mode ***
int data_Clr = 0x00; // Bin val B00000000, Dec val 0, Oct val 0, [ 8 bit size = 1 byte ]
int data_1 = 0x0f; // Bin val B00001111, Dec val 15 Oct val 17, [ 8 bit size = 1 byte ]
int data_2 = 0xf0; // Bin val B11110000, Dec val 240 Oct val 360, [ 8 bit size = 1 byte ]
int data_3 = 0x40; // Bin val B01000000, Dec val 64 Oct val 100, [ 8 bit size = 1 byte ]
int data_4 = 0x00; // Bin val B00000000, Dec val 0 Oct val 0, [ 8 bit size = 1 byte ]

int t = 1000; // Clear shift register timer [ milliseconds 1000 = 1 second ]
int t_1 = 500; // Switch timer [ milliseconds 500 = .5 secomd ]

void setup() { // Setup will only run the code once, until the arduino has been powered down / reset.

pinMode (ds_Input, OUTPUT); // Setup pins as outputs
pinMode (sh_Input, OUTPUT); //
pinMode (st_Input, OUTPUT); //

digitalWrite( st_Input, LOW ); // Sending byte data
shiftOut( ds_Input, sh_Input, LSBFIRST, data_Clr ); // clear second shift register 0x00
shiftOut( ds_Input, sh_Input, LSBFIRST, data_Clr ); // clear first shift register 0x00
digitalWrite( st_Input, HIGH ); // Stop sending byte data
delay(t);

}

/* ** Excerise **
// could change LSBFIRST to MSBFIRST and see the differance in direction.
// make or change the data_x variable to see how the LED bits light up.
// make or change t_1 timer variable to see how this works.
// Sets bits on first register and disconnect the wire from pin 9 and wire to pin 14 to see what happens.
// Make counter for loop etc.
*/

void loop() { // Program loop forever

test_1(); // Goto test_1
test_2(); // Goto test_2

}

void test_1() {

digitalWrite ( st_Input, LOW );
shiftOut ( ds_Input, sh_Input, LSBFIRST, data_1 ); // Sends 1 byte to second register
shiftOut ( ds_Input, sh_Input, LSBFIRST, data_4 ); // Sends 1 byte to first register
digitalWrite ( st_Input, HIGH );
delay(t_1);
// Return to loop, to next line in statement
}

void test_2() {

digitalWrite ( st_Input, LOW );
shiftOut ( ds_Input, sh_Input, LSBFIRST, data_2 ); // Sends 1 byte to second register
shiftOut ( ds_Input, sh_Input, LSBFIRST, data_4 ); // Sends 1 byte to first register
digitalWrite ( st_Input, HIGH );
delay(t_1);
// Return to loop, to next line in statement
}