Clock + Possibility for Safe/lock
by OscarNilsson in Living > Hiding Places
1524 Views, 20 Favorites, 0 Comments
Clock + Possibility for Safe/lock
Function description
Our project is a full functional clock. On the front there is 60 LEDs, one for every second, and on top of the clock we have placed a segment LED display that keeps track of the minutes and hours. As an extra feature we have installed a potentiometer that is connected to the LEDs and when you turn the potentiometer you control which of the 60 LEDs that is going to light. The main purpose with this extra feature was to be able to put in a secret code that would then lock up the box, like a strongbox.
Component list
• 60st RGB LEDs driven by HC595 constant current LED drivers
• 4x HC595 with 16 outputs each
• 4x 7 segment LED display
• DS1307 real time clock
• Photo resistor (for adjusting brightness)
• Potentiometer
• Switch (On/Off-button)
Code:
//Led int latchPin = 2;
int clock = 4;
int dataPin = 2;
//Buttons
int ButtonPin = 13;
int analogPin = A0;
//Clock int APin = 5;
int BPin = 6;
int CPin = 7;
int DPin = 8;
unsigned long previousTime = 0;
int Hour = 11;
int Minute = 36;
int Second = 0;
int HourTen = 0;
int MinuteTen = 0;
int Hourunit = 0;
int Hour1 = 0;
int Minuteunit = 0;
int minute = 0;
int HourPin = 9;
int HourunitPin = 10;
int MinutePin = 11;
int MinuteunitPin = 12;
unsigned long interval = 1000;
void setup (){
pinMode(analogPin, INPUT);
pinMode(ButtonPin, INPUT_PULLUP);
//led Pins
pinMode(latchPin, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(dataPin, OUTPUT);
//Clock Pins
pinMode(APin, OUTPUT);
pinMode(BPin, OUTPUT);
pinMode(CPin, OUTPUT);
pinMode(DPin, OUTPUT);
pinMode(HourPin, OUTPUT);
pinMode(HourunitPin, OUTPUT);
pinMode(MinutePin, OUTPUT);
pinMode(MinuteunitPin, OUTPUT);
Serial.begin(9600);
}
void loop () {
unsigned long currentTime = millis();
if (digitalRead(ButtonPin) == LOW) {
int val = analogRead(analogPin);
val = map(val, 0, 1023, 0, 60);
lightlednr(val);
}
else {
if ((currentTime - previousTime) > interval) {
Second = Second++;
previousTime = currentTime;
Serial.print(Hour);
Serial.print(":");
Serial.print(Minute);
Serial.print(":");
Serial.println(Second);
// Serial.print(bitRead(digit,3));
// Serial.print(bitRead(digit,2));
// Serial.print(bitRead(digit,1));
// Serial.println(bitRead(digit,0));
}
if ( Second == 60) {
Second = 0;
Minute = Minute++;
}
if ( Minute == 60) {
Minute = 0;
Hour = Hour++;
}
if ( Hour == 24) {
Hour = 0;
}
// one second has passed
Minuteunit = Minute % 10;
MinuteTen = (Minute - Minuteunit) / 10;
Hourunit = Hour % 10;
HourTen = (Hour - Hourunit) / 10;
UpdateClock(); lightlednr(Second);
}
}
// Serial.print(Hour);
// Serial.print(":");
// Serial.print(Minute);
// Serial.print(":");
// Serial.println(Second);
void UpdateClock() {
digitalWrite (HourPin, HIGH);
showdigit( HourTen);
delay(5);
digitalWrite(HourPin, LOW);
digitalWrite (HourunitPin, HIGH);
showdigit( Hourunit);
delay(5);
digitalWrite(HourunitPin, LOW);
digitalWrite (MinutePin, HIGH);
showdigit( MinuteTen);
delay(5);
digitalWrite(MinutePin, LOW);
digitalWrite (MinuteunitPin, HIGH);
showdigit( Minuteunit);
delay(5);
digitalWrite(MinuteunitPin, LOW);
}
void showdigit (int digit) {
digitalWrite(APin, bitRead(digit,0));
digitalWrite(BPin, bitRead(digit,1));
digitalWrite(CPin, bitRead(digit,2));
digitalWrite(DPin, bitRead(digit,3));
// Serial.print(bitRead(digit,3));
// Serial.print(bitRead(digit,2));
// Serial.print(bitRead(digit,1));
// Serial.println(bitRead(digit,0));
//
}
void lightlednr(byte lednr){
digitalWrite(latchPin, LOW);
Serial.println(lednr, BIN);
byte shbyte=0;
if (lednr<8){
shiftOut(dataPin, clock, LSBFIRST,bitWrite(shbyte,(lednr % 8),1));
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
}
else if (lednr<16){
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, LSBFIRST,bitWrite(shbyte,(lednr % 8),1));
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
}
else if (lednr<24){
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, LSBFIRST,bitWrite(shbyte,(lednr % 8),1));
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
}
else if (lednr<32){
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, LSBFIRST,bitWrite(shbyte,(lednr % 8),1));
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
}
else if (lednr<40){ shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, LSBFIRST,bitWrite(shbyte,(lednr % 8),1));
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
}
else if (lednr<48){ shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, LSBFIRST,bitWrite(shbyte,(lednr % 8),1));
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
}
else if (lednr<56){
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, LSBFIRST,bitWrite(shbyte,(lednr % 8),1));
shiftOut(dataPin, clock, MSBFIRST,0);
}
else if (lednr<64){
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, MSBFIRST,0);
shiftOut(dataPin, clock, LSBFIRST,bitWrite(shbyte,(lednr % 8),1));
}
digitalWrite(latchPin, HIGH);
}