Here is the code below to operate LEDs at some of the outputs of same Arduino UNO on which A
74165 is applied to operate multiple outs with only 2 inputs
/*
74HC165 Shift Register Demonstration 1
74hc165-demo.ino
Read from 8 switches and display values on serial monitor
DroneBot Workshop 2020
https://dronebotworkshop.com
*/
// Define Connections to 74HC165
// PL pin 1
int load = 7;
// CE pin 15
int clockEnablePin = 4;
// Q7 pin 7
int dataIn = 5;
// CP pin 2
int clockIn = 6;
int led1 = 8;
int led2 = 9;
int led3 = 10;
int led4 = 11;
void setup()
{
// Setup Serial Monitor
Serial.begin(9600);
// Setup 74HC165 connections
pinMode(load, OUTPUT);
pinMode(clockEnablePin, OUTPUT);
pinMode(clockIn, OUTPUT);
pinMode(dataIn, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
digitalWrite(led1,1);
delay(250);
digitalWrite(led2,1);
delay(250);
digitalWrite(led1,0);
delay(250);
digitalWrite(led2,0);
}
void loop()
{
// Write pulse to load pin
digitalWrite(load, LOW);
delayMicroseconds(5);
digitalWrite(load, HIGH);
delayMicroseconds(5);
// Get data from 74HC165
digitalWrite(clockIn, HIGH);
digitalWrite(clockEnablePin, LOW);
byte incoming = shiftIn(dataIn, clockIn, LSBFIRST);
digitalWrite(clockEnablePin, HIGH);
// Print to serial monitor
Serial.print("Pin States:\r\n");
Serial.println(incoming, BIN);
delay(1000);
if(incoming=10111111)
{
digitalWrite(led1,1);
}
else
{
digitalWrite(led1,0);
}
}
The 165 is an input shift register (parallel to serial - good for button - see your drawing).
The 595 is an output shift register (serial to parallel - good for LEDs). Example.