Here the code is - not very cleaned up at all
The only thing I would recommend watching out for is the scanlimit section - make sure these settings correspond properly if you use it.
#include <DateTime.h>
#include <DateTimeStrings.h>
//We always have to include the library
#include "LedControl.h"
#define START_TIME 1230393840 // set this to the Unix start time you want (0 is midnight Jan1 1970 UTC)
/* Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,11,10,1);
/* we always wait a bit between updates of the display */
unsigned long delaytime=500;
unsigned long delaytime1=50;
int countones=0;
int counttens=0;
int counthuns=0;
int countthos=0;
byte hours1;
char minutes = '0';
char seconds = '0';
int secondstens = 0;
int secondsones = 0;
int hoursones = 0;
int hourstens = 0;
int minutesones = 0;
int minutestens = 0;
void setup(){
Serial.begin(19200);
DateTime.sync(START_TIME);
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,15);
/* and clear the display */
lc.setScanLimit(2,15);
lc.clearDisplay(0);
pinMode (minbutton, INPUT);
pinMode (minbuttonm, INPUT);
pinMode (hourbutton, INPUT);
pinMode (hourbuttonm, INPUT);
}
void loop(){
unsigned long prevtime;
delay(400);
DateTime.available();
showcurtime();
}
void showcurtime(){
byte hours2;
hours1 = 0;
hours1 = (DateTime.Hour);
hours2 = hours24To12(hours1);
hoursones = hours2 % 10;
hourstens = hours2;
if (hourstens > 9) {
hourstens = hourstens / 10;
}
else {
hourstens = 0;
}
secondsones = (DateTime.Second) % 10;
secondstens = (DateTime.Second);
if (secondstens > 9) {
secondstens = secondstens / 10;
}
else {
secondstens = 0;
}
minutesones = (DateTime.Minute) % 10;
minutestens = (DateTime.Minute);
if (minutestens > 9) {
minutestens = minutestens / 10;
}
else {
minutestens = 0;
}
printDigits1(hoursones);
printDigits1(hourstens);
lc.setChar(0,1,minutestens,false);
lc.setChar(0,0,minutesones,false);
lc.setChar(0,2,hoursones,false);
if (hourstens == 0) {
lc.setChar(0,3,'-',false);
}
else lc.setChar(0,3,hourstens,false);
}
byte hours24To12(byte hours){
if( hours == 0 )
return 12; // 12 midnight
else if( hours > 12)
return hours - 12 ;
else
return hours ;
}