//PINS for Ones and Tens, no Serial on 0/1
byte oneS[] = {0,1,2,3,4,5,6,7,8}; byte tenS[] = {9,10,11,12,13}; // 1-9; 10-50
byte theSwitch[] = {A0,A1,A2}; // LED GND
int s10=3,s1=0; //set Sec
int m10=5,m1=9; //set Min
int h10=2,h1=3; //set Hour

unsigned long t,t0; //TIME in ms
unsigned long TIMEREAD(void){return millis()-t0;}
void TIMEINIT(){t0 = millis();}

void setup() 
{ int i;
  for(i=0; i<sizeof(oneS);i++)pinMode(oneS[i],OUTPUT);
  for(i=0; i<sizeof(tenS);i++)pinMode(tenS[i],OUTPUT);
  for(i=0; i<sizeof(theSwitch);i++)pinMode(theSwitch[i],OUTPUT);
  for(i=0; i<sizeof(theSwitch);i++)digitalWrite(theSwitch[i],HIGH);
  //TIMEINIT();
}

void loop() 
{ int i, sim = 300; //ShowTime in ms, change to 30 multplex more real
  t = TIMEREAD();
  do
  { for(i = 0;i<sizeof(oneS);i++)digitalWrite(oneS[i],s1>i);    //Sec 01
    for(i = 0;i<sizeof(tenS);i++)digitalWrite(tenS[i],s10>i);   //Sec 10 
    digitalWrite(A1,1);digitalWrite(A2,1); digitalWrite(A0,0);  //Sec Showtime
    delay(sim);          
    for(i = 0;i<sizeof(oneS);i++)digitalWrite(oneS[i],m1>i);    //Min 01
    for(i = 0;i<sizeof(tenS);i++)digitalWrite(tenS[i],m10>i);   //Min 10 
    digitalWrite(A0,1); digitalWrite(A2,0);digitalWrite(A1,0);  //Min ShowTime
    delay(sim);
    for(i = 0;i<sizeof(oneS);i++)digitalWrite(oneS[i],h1>i);    //Hr  01
    for(i = 0;i<sizeof(tenS);i++)digitalWrite(tenS[i],h10>i);   //Hr  10
    digitalWrite(A0,1);digitalWrite(A1,1); digitalWrite(A2,0);  //Hr  ShowTime
    delay(sim);
  }while(TIMEREAD()<(t+500)); // Realtime: (t+1000) for one second
  //- The Clock -
  s1++;                   //s++;
  if(s1>=10){s1=0;s10++;} 
  if(s10>=6){s10=0;m1++;} //m1++;
  if(m1>=10){m1=0;m10++;}
  if(m10>=6){m10=0;h1++;} //h1++;
  if(h1>=10){h1=0;h10++;}
  if(h10>=2 && h1>=4){h10=0;h1=0;}
}