Shifting Bits With Arduino

I've recently started back into electronics. I took an electronics course back in high school, but I've dealt mostly with software since then.I've had a Freeduino-SB sitting around since last year, until I finally soldered on the through hole components a few weeks ago. The Freeduino is an Arduino clone made by Solarbotics.

So far, I've managed to power a dual digit 7 segment display using two 74HC595 shift registers. These can be chained in series to provide more outputs from the same three output pins from the Arduino.

Arduino Countdown Here's a video of the code in action. The initial state of the 7 segment display is randomly determined, as one of the pins on the shift registers is connected directly to power, instead of an additional output pin. [youtube=]

Here's the rather basic code I'm currently using:

//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 8;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 12;
//Pin connected to Data in (DS) of 74HC595
const int dataPin = 11;

long count = 0;

void setup() {
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
  //Reset display
  byte bits = 0;
  writeDigit(bits, bits);

byte getByteForDigit(int digit){
  byte bit = 0;
      case 1:
        bit = B110;
      case 2:
        bit = B1011011;
      case 3:
        bit = B1001111;
      case 4:
        bit = B1100110;
      case 5:
        bit = B1101101;
      case 6:
        bit = B1111101;
      case 7:
        bit = B111;
      case 8:
        bit = B1111111;
      case 9:
        bit = B1100111;
      case 0:
        bit = B111111;
    return bit;

void loop() {
    byte bits = 0;
    byte bits2 = 0;
    bits = getByteForDigit((100-count) % 10);
    bits2 = getByteForDigit((100-count) / 10);
    writeDigit(bits, bits2);
    count = (count + 1) % 100;

void writeDigit(byte bits, byte bits2){

  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, bits);
  shiftOut(dataPin, clockPin, MSBFIRST, bits2);
  digitalWrite(latchPin, HIGH);