/*
* 7HC595 4-Digit Diagnostic Test
* Displays the same digit (0-9) on all modules at once.
*/
const int DATA_PIN = 11; // DS
const int LATCH_PIN = 12; // STCP
const int CLOCK_PIN = 13; // SHCP
// Segment map for 0–9 (Common Cathode)
// Bit order: DP G F E D C B A
const byte DIGIT_MAP[10] = {
0b00111111, // 0
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
0b01100110, // 4
0b01101101, // 5
0b01111101, // 6
0b00000111, // 7
0b01111111, // 8
0b01101111 // 9
};
void setup() {
pinMode(DATA_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
}
// Sends the same byte to all 4 shift registers
void sendToAll(byte pattern) {
digitalWrite(LATCH_PIN, LOW);
// Shift out the same pattern 4 times
for (int i = 0; i < 4; i++) {
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, pattern);
}
digitalWrite(LATCH_PIN, HIGH);
}
void loop() {
// Cycle through numbers 0 to 9
for (int num = 0; num <= 9; num++) {
// Test 1: Display the number without Decimal Point
sendToAll(DIGIT_MAP[num]);
delay(800);
// Test 2: Display the number WITH Decimal Point (checks bit 7)
sendToAll(DIGIT_MAP[num] | 0b10000000);
delay(200);
}
}