// 74HC595
const int dataPin595 = 11; // DS
const int clockPin595 = 12; // SHCP
const int latchPin595 = 13; // STCP
// 74HC165
const int dataPin165 = 8; // Q7
const int clockPin165 = 9; // CP
const int latchPin165 = 10; // PL
const byte dataArray[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
void setup() {
// 74HC595
pinMode(dataPin595, OUTPUT);
pinMode(clockPin595, OUTPUT);
pinMode(latchPin595, OUTPUT);
// 74HC165
pinMode(dataPin165, INPUT);
pinMode(clockPin165, OUTPUT);
pinMode(latchPin165, OUTPUT);
Serial.begin(9600);
}
void loop() {
// Cycle through columns and enable them one by one
for ( int i = 0; i < 8; i++) {
digitalWrite(latchPin595, LOW);
shiftOut(dataPin595, clockPin595, LSBFIRST, dataArray[i]);
digitalWrite(latchPin595, HIGH);
// Cycle through the rows and sample
digitalWrite(latchPin165, LOW);
digitalWrite(latchPin165, HIGH);
/*
for (int j = 0; j < 8; j++) {
int bit = digitalRead(dataPin165);
if (bit == HIGH) {
Serial.print("column: ");
Serial.print(i+1);
Serial.print(" row: ");
Serial.print(j+1);
Serial.println();
}
digitalWrite(clockPin165, HIGH); // Shift out the next bit
digitalWrite(clockPin165, LOW);
}
*/
// Step 2: Shift
Serial.print("Bits: ");
for (int i = 0; i < 8; i++) {
int bit = digitalRead(dataPin165);
if (bit == HIGH) {
Serial.print("1");
} else {
Serial.print("0");
}
digitalWrite(clockPin165, HIGH); // Shift out the next bit
digitalWrite(clockPin165, LOW);
}
Serial.println();
delay(500);
}
}