#include <SPI.h>
const int latchPin = 10; // Connects to Pin 12 (Latch/ST_CP) on 74HC595
const int dataPin = 11; // Connects to Pin 14 (Data/SI) on 74HC595
const int clockPin = 13; // Connects to Pin 11 (Clock/SH_CP) on 74HC595
void setup() {
Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop() {
// Read button states
byte buttonsState = readButtons();
// Print button states
Serial.print("Button States: ");
for (int i = 0; i < 8; ++i) {
Serial.print(bitRead(buttonsState, i));
}
Serial.println();
delay(500); // Add a delay to avoid fast button state changes
}
byte readButtons() {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, B11111111); // Shift in all 8 bits
digitalWrite(latchPin, HIGH);
return digitalRead(0); // Replace 0 with the appropriate pin number where the Q0 is connected
}