/* Ths is my Binary Clock: +Designed with Hours, Minuets, and Seconds +Uses 1 ATtiny84, 1 SN84HC164N, and 6 PN2222 Transisters +2 Buttons for Hour and Minuet setting Note: I used multiplexing to acces each coloum of the display one at a time this freed up more space on the ATtiny 84. If you dont need to use two buttons or have more than 11 I/O then you could connect the transistors directly to your device and then relay the clocking high and low with a digitalWrite function to whatever layer you want on. An open-source binary clock for Arduino. */ #define clock 0 #define data 1 #define button1 2 //Left Button #define button2 3 //Right Button #define layer0 5//Botom #define layer1 6 #define layer2 7 #define layer3 8 //Top //start the time on 00:00:00 int second=0, minute=0, hour=0; int mUnit = 0; int hUnit = 0; int sUnit = 0; int minButton = 0; int hourButton = 0; unsigned long testTime = 1000; // for configuring the length of 1 second void setup() { pinMode(clock, OUTPUT); pinMode(data, OUTPUT); pinMode(button1, INPUT); pinMode(button2, INPUT); pinMode(layer0, OUTPUT); pinMode(layer1, OUTPUT); pinMode(layer2, OUTPUT); pinMode(layer3, OUTPUT); //Begining of a custom configuration for the value of one second shiftOut(data, clock, LSBFIRST, 0xff); digitalWrite(layer3, HIGH); //if you press hours button it will be the default time of 1000 milliseconds/ second while(minButton == 0 && hourButton == 0) { minButton = digitalRead(button1); hourButton = digitalRead(button2); } //this sets the tick interval to whatever your time keeper wants... //example. your watch runs slower then the arduino, this will fix that... //do it for 60 seconds for better accuracy //press the HOUR BUTTON at the end of 60 sec if(minButton != 0) { digitalWrite(layer0, HIGH); unsigned long timeTemp = millis(); hourButton = 0; while(hourButton == 0) { hourButton = digitalRead(button2); testTime = millis() - timeTemp; } digitalWrite(layer2, HIGH); delay(500); testTime = testTime/60; // change the 60 if you dont want to wait, but a longer time is more accurate } delay(250); minButton = 0; hourButton = 0; } void loop() { // variable for moving forard one second static unsigned long lastSecond = 0; //my clock was a little fst so added a setup configuration if (millis() - lastSecond >= testTime) { lastSecond = millis(); second++; } // move forward one minute every 60 seconds if (second >= 60) { minute++; second = 0; // reset seconds to zero } // move forward one hour every 60 minutes if (minute >= 60) { hour++; minute = 0; // reset minutes to zero } //only used if you want to subteact minutes instead of adding /* if (minute < 0) { minute = 59; second = 0; }*/ //resets the clock after 24 hours if (hour >= 24) { hour=0; minute = 0; // reset minutes to zero } //sets the variable sUnit, mUnit and hUnit for the unit digits sUnit = second%10; mUnit = minute%10; hUnit = hour%10; // adds one minute when pressed minButton = digitalRead(button1); if(minButton == HIGH) { minute++; second=0; delay(250); } // add one hour when pressed hourButton = digitalRead(button2); if(hourButton == HIGH) { hour++; second=0; delay(250); } activate(); } void activate() { //writes HIGH and then shifts the shift registor while activating the layers int temp = 1; digitalWrite(clock, LOW); digitalWrite(data, HIGH); digitalWrite(clock, HIGH); digitalWrite(data, LOW); layer(1); delay(temp); led(LOW, LOW, LOW, LOW); digitalWrite(clock, LOW); digitalWrite(clock, HIGH); layer(2); delay(temp); led(LOW, LOW, LOW, LOW); digitalWrite(clock, LOW); digitalWrite(clock, HIGH); layer(3); delay(temp); led(LOW, LOW, LOW, LOW); digitalWrite(clock, LOW); digitalWrite(clock, HIGH); layer(4); delay(temp); led(LOW, LOW, LOW, LOW); digitalWrite(clock, LOW); digitalWrite(clock, HIGH); layer(5); delay(temp); led(LOW, LOW, LOW, LOW); digitalWrite(clock, LOW); digitalWrite(clock, HIGH); layer(6); delay(temp); led(LOW, LOW, LOW, LOW); digitalWrite(clock, LOW); digitalWrite(clock, HIGH); digitalWrite(clock, LOW); digitalWrite(clock, HIGH); digitalWrite(clock, LOW); digitalWrite(clock, HIGH); } void layer(int bits) { //this function inputs what layer it is on and then truns on //the LEDs for that layer byte one; byte two; byte four; byte eight; switch(bits) { case 1: if(sUnit == 1 || sUnit == 3 || sUnit == 5 || sUnit == 7 || sUnit == 9) { one = HIGH; } else { one = LOW; } if(sUnit == 2 || sUnit == 3 || sUnit == 6 || sUnit == 7) { two = HIGH; } else { two = LOW; } if(sUnit == 4 || sUnit == 5 || sUnit == 6 || sUnit == 7) { four = HIGH; } else { four = LOW; } if(sUnit == 8 || sUnit == 9) { eight = HIGH; } else { eight = LOW; } if (sUnit == 0) { one = LOW; two = LOW; four = LOW; eight = LOW; } led(one, two, four, eight); break; case 2: if((second >= 10 && second < 20) || (second >= 30 && second < 40) || (second >= 50 && second < 60)) { one = HIGH; } else { one = LOW; } if(second >= 20 && second < 40) { two = HIGH; } else { two = LOW; } if(second >= 40 && second < 60) { four = HIGH; } else { four = LOW; } if (second == 0) { one = LOW; two = LOW; four = LOW; eight = LOW; } led(one, two, four, eight); break; case 3: if(mUnit == 1 || mUnit == 3 || mUnit == 5 || mUnit == 7 || mUnit == 9) { one = HIGH; } else { one = LOW; } if(mUnit == 2 || mUnit == 3 || mUnit == 6 || mUnit == 7) { two = HIGH; } else { two = LOW; } if(mUnit == 4 || mUnit == 5 || mUnit == 6 || mUnit == 7) { four = HIGH; } else { four = LOW; } if(mUnit == 8 || mUnit == 9) { eight = HIGH; } else { eight = LOW; } if (mUnit == 0) { one = LOW; two = LOW; four = LOW; eight = LOW; } led(one, two, four, eight); break; case 4: if((minute >= 10 && minute < 20) || (minute >= 30 && minute < 40) || (minute >= 50 && minute < 60)) { one = HIGH; } else { one = LOW; } if(minute >= 20 && minute < 40) { two = HIGH; } else { two = LOW; } if(minute >= 40 && minute < 60) { four = HIGH; } else { four = LOW; } if (minute == 0) { one = LOW; two = LOW; four = LOW; eight = LOW; } led(one, two, four, eight); break; case 5: if(hUnit == 1 || hUnit == 3 || hUnit == 5 || hUnit == 7 || hUnit == 9) { one = HIGH; } else { one = LOW; } if(hUnit == 2 || hUnit == 3 || hUnit == 6 || hUnit == 7) { two = HIGH; } else { two = LOW; } if(hUnit == 4 || hUnit == 5 || hUnit == 6 || hUnit == 7) { four = HIGH; } else { four = LOW; } if(hUnit == 8 || hUnit == 9) { eight = HIGH; } else { eight = LOW; } if (hUnit == 0) { one = LOW; two = LOW; four = LOW; eight = LOW; } led(one, two, four, eight); break; case 6: if(hour >= 20 && hour < 24) { one = LOW; two = HIGH; four = LOW; eight = LOW; } if(hour >= 10 && hour < 20) { one = HIGH; two = LOW; four = LOW; eight = LOW; } if (hour <= 9) { one = LOW; two = LOW; four = LOW; eight = LOW; } led(one, two, four, eight); break; } } void led(byte ichi, byte ni, byte yon, byte hachi) { digitalWrite(layer0, ichi); digitalWrite(layer1, ni); digitalWrite(layer2, yon); digitalWrite(layer3, hachi); }