int load = A0; // PL pin 1 of both registers
int clockEnablePin = A1; // CE pin 15 of both register
int dataIn = A3; // Q7 pin 9 of the second 74HC165, Pin 9 of first register goes to pin 10 of 2nd
int clockIn = A2; // CP pin 2 of both
byte inputData[2] = {B00000000, B00000000}; // Array to store the incoming data
void setup()
{
// Setup Serial Monitor
Serial.begin(9600);
// Setup 74HC165 connections
pinMode(load, OUTPUT);
pinMode(clockEnablePin, OUTPUT);
pinMode(clockIn, OUTPUT);
pinMode(dataIn, INPUT);
}
void loop()
{
// Load parallel data into the shift registers
digitalWrite(load, LOW);
delayMicroseconds(10);
digitalWrite(load, HIGH);
delayMicroseconds(10);
// Enable the clock and read the data into the array
digitalWrite(clockEnablePin, LOW);
//digitalWrite(clockIn, HIGH);
// digitalWrite(clockIn, LOW);
inputData[0] = shiftIn(dataIn, clockIn, LSBFIRST); // Read 8 bits from the first shift register
inputData[1] = shiftIn(dataIn, clockIn, LSBFIRST); // Read 8 bits from the second shift register
digitalWrite(clockEnablePin, HIGH);
// Print the data with all 8 bits
// Serial.println("Shift Register States:");
Serial.print("Register 1: ");
printBinary8(inputData[0]); // Print the first register's data as 8-bit binary
Serial.print("\t");
Serial.print("Register 2: ");
printBinary8(inputData[1]); // Print the second register's data as 8-bit binary
Serial.println();
delay(1000); // Delay for readability
}
// Function to print a byte as 8-bit binary
void printBinary8(byte value)
{
for (int i = 7; i >= 0; i--) {
Serial.print((value >> i) & 1); // Print each bit
}
//Serial.println(); // Newline for the next print
}