Domino Clock

#include <Time.h>


//Data Lines to the hour stone
int hlatchPin = 3;
int hclockPin = 4;
int hdataPin = 5;

//Data Lines to the decimal minute stone
int dlatchPin = 6;
int dclockPin = 7;
int ddataPin = 8;

//Data Lines to the single minute stone
int mlatchPin = 9;
int mclockPin = 10;
int mdataPin = 11;

int h = 0;
int m = 0;
int mins = 0;
int d = 0;
int previousHours = 0;
int previousMins = 0;

byte number_to_display;

//hour and minute adjust buttons
const int hourPin = 12;
const int minPin = 13;

[color=red]int hours_display[13];
number_to_display[0] = B0000000000000000;
number_to_display[1] = 0000000001000000;
number_to_display[2] = 0100000001000000;
number_to_display[3] = 0100000000100100;
number_to_display[4] = 0010010000100100;
number_to_display[5] = 0010010001100100;
number_to_display[6] = 0110010001100100;
number_to_display[7] = 0110010000101101;
number_to_display[8] = 0010110100101101;
number_to_display[9] = 0010110101101101;
number_to_display[10] = 0110110101101101;
number_to_display[11] = 0110110100111111;
number_to_display[12] = 0011111100111111;[/color]

void setup() {

  pinMode(hlatchPin, OUTPUT);
  pinMode(hclockPin, OUTPUT);
  pinMode(hdataPin, OUTPUT);

  pinMode(dlatchPin, OUTPUT);
  pinMode(dclockPin, OUTPUT);
  pinMode(ddataPin, OUTPUT);

  pinMode(mlatchPin, OUTPUT);
  pinMode(mclockPin, OUTPUT);
  pinMode(mdataPin, OUTPUT);

[color=red]  pinMode(hourPin, INPUT);
  pinMode(minPin, INPUT);[/color]

[color=red]
int hourState = digitalRead(hourPin);
int minState = digitalRead(minPin);

int buttonState;             // the current hourstate from the input pin
int lastButtonState = LOW;   // the previous hourstate from the input pin
int buttonState2;             // the current hourstate from the input pin
int lastButtonState2 = LOW;   // the previous hourstate from the input pin

long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers

//Hour adjustment
// if the button is pressed
// 1) reset the debouncing timer
// 2) take the debounce delay as the current state
// 3) Set time
// 4) save the hourstat

if (hourState == HIGH) {

  lastDebounceTime = millis();

  if ((millis() - lastDebounceTime) > debounceDelay) {
    buttonState = hourstate;
  }

  time_t t = now();
  t = t + 3600;
  setTime(t);

  lastButtonState = hourstate;

}

//Minute adjustment
if (minState == HIGH) {

  lastDebounceTime = millis();

  if ((millis() - lastDebounceTime) > debounceDelay) {
    buttonState2 = minstate;
  }

  time_t t = now();
  t = t + 60;
  setTime(t);
  lastButtonState2 = minstate;
}[/color]
}

void loop() {

    h = hourFormat12();
    m = minute();

    if(previousHours != h) {
	digitalWrite(hlatchPin, LOW);
	shiftOut(hdataPin, hclockPin, MSBFIRST, (number_to_display[h] >> 8 ));
	shiftOut(hdataPin, hclockPin, MSBFIRST, hours_display[h]);

	digitalWrite(hlatchPin, HIGH);
	previousHours = h;
    }
    if(previousMins != m) {
	mins = m;
	if(mins >= 10) {
	  d = 0;
	  while(mins >= 10) {
	    mins = mins - 10;
	    d = d + 1;
	  }
	  digitalWrite(dlatchPin, LOW);
	  shiftOut(ddataPin, dclockPin, MSBFIRST, (number_to_display[d] >> 8 ));
          shiftOut(ddataPin, dclockPin, MSBFIRST, number_to_display[d]);

	  digitalWrite(dlatchPin, HIGH);
	  digitalWrite(mlatchPin, LOW);
          shiftOut(mdataPin, mclockPin, MSBFIRST, (number_to_display[mins] >> 8 ));
          shiftOut(mdataPin, mclockPin, MSBFIRST, number_to_display[mins]);

	  digitalWrite(mlatchPin, HIGH);
	}
	else {
	  digitalWrite(dlatchPin, LOW);
	  shiftOut(ddataPin, dclockPin, MSBFIRST, 0);
	  shiftOut(ddataPin, dclockPin, MSBFIRST, 0);
	  shiftOut(ddataPin, dclockPin, MSBFIRST, 0);
	  digitalWrite(dlatchPin, HIGH);
	  digitalWrite(mlatchPin, LOW);
          shiftOut(mdataPin, mclockPin, MSBFIRST, (number_to_display[mins] >> 8 ));
          shiftOut(mdataPin, mclockPin, MSBFIRST, number_to_display[mins]);
	  digitalWrite(mlatchPin, HIGH);
	}
	previousMins = m;
    }

}