#include <Arduino.h>
const uint8_t LATCH_PIN = 3;
const uint8_t CLOCK_PIN = 4;
const uint8_t DATA_PIN = 2;
// Bit 7 is segment a, then b,c,d,e,f,g,dp. LSBFIRST moves bit 7 into Q0.
const uint8_t DIGITS[10] = {0b11111100,0b01100000,0b11011010,0b11110010,0b01100110,
                            0b10110110,0b10111110,0b11100000,0b11111110,0b11100110};
// This function uses digit as an array index, then latches the complete pattern at once.
void sevenSegWrite(uint8_t digit) {
  digitalWrite(LATCH_PIN, LOW);
  shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, DIGITS[digit]);
  digitalWrite(LATCH_PIN, HIGH);
}
void setup() {
  pinMode(LATCH_PIN, OUTPUT); pinMode(CLOCK_PIN, OUTPUT); pinMode(DATA_PIN, OUTPUT);
}
void loop() {
  // Count with a positive counter to avoid an unsigned byte wrapping below zero.
  for (uint8_t digit = 10; digit > 0; --digit) {
    delay(1000); sevenSegWrite(digit - 1);
  }
  delay(1000);  // The executable source waits one extra second, despite a '4 seconds' comment.
}
