#include "LedControl.h"
/*
Now we need a LedControl to work with.
pin 12 is connected to the DataIn
pin 11 is connected to LOAD
pin 10 is connected to the CLK
*/
LedControl lc=LedControl(12,10,11,1);
const int seth = 4;
const int setm = 3;
const int setc = 2;
int second ;
int minute ;
int hour ;
int correction = 0;
unsigned long previousMillis = 0;
const long interval = 1000;
void setup() {
lc.shutdown(0,false);
lc.setIntensity(0,12);
lc.clearDisplay(0);
}
void loop() {
if (digitalRead(seth)== HIGH){
hour++;
delay(200);
if(hour>23){
hour=00;
}
}
if (digitalRead(setm)== HIGH){
minute++;
delay(200);
if(minute>59){
minute=00;
}
}
if (digitalRead(setc)== HIGH){
correction++;
delay(200);
if(correction>59){
correction=00;
}
}
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
second++;
if(second>59)
{
minute++;
second=00;
}
if(minute>59)
{
hour++;
minute=00;
second = second + correction;
}
if(hour>23) { hour=00; minute=00; second=correction; }
}
lc.setDigit(0,1,hour % 10,true);
lc.setDigit(0,0,(hour - hour % 10) / 10,false);
lc.setDigit(0,3,minute % 10,false);
lc.setDigit(0,2,(minute - minute % 10) / 10,false);
lc.setDigit(0,5,second % 10,true);
lc.setDigit(0,4,(second - second % 10) / 10,false);
lc.setDigit(0,7,correction % 10,false);
lc.setDigit(0,6,(correction - correction % 10) / 10,false);
}
Comments