bool common_anode = true;
bool On = !common_anode;
bool Off =  common_anode;

int num1 = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;

int ports[] = {13,12,11,10,9,8,7,6};

void setup() {
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);

  attachInterrupt(0,interrupt,FALLING);
}

void Symbol(int symbol,bool isdp,int digit, int a = ports[0],int b=ports[1],int c=ports[2],int d=ports[3],int e=ports[4],int f=ports[5],int g=ports[6],int dp=ports[7]){

  switch (symbol){
    case 0:
    digitalWrite(a, On);
    digitalWrite(b, On);
    digitalWrite(c, On);
    digitalWrite(d, On);
    digitalWrite(e, On);
    digitalWrite(f, On);
    digitalWrite(g, Off);
    //digitalWrite(dp, !isdp);
    break;
    case 1:
    digitalWrite(a, Off);
    digitalWrite(b, On);
    digitalWrite(c, On);
    digitalWrite(d, Off);
    digitalWrite(e, Off);
    digitalWrite(f, Off);
    digitalWrite(g, Off);
    //digitalWrite(dp, !isdp);
    break;
    case 2:
    digitalWrite(a, On);//
    digitalWrite(b, On);//
    digitalWrite(c, Off);
    digitalWrite(d, On);
    digitalWrite(e, On);//
    digitalWrite(f, Off);
    digitalWrite(g, On);//
    //digitalWrite(dp, !isdp);
    break;
    case 3:
    digitalWrite(a, On);//
    digitalWrite(b, On);//
    digitalWrite(c, On);//
    digitalWrite(d, On);//
    digitalWrite(e, Off);
    digitalWrite(f, Off);
    digitalWrite(g, On);//
    //digitalWrite(dp, !isdp);
    break;
    case 4:
    digitalWrite(a, Off);
    digitalWrite(b, On);//
    digitalWrite(c, On);//
    digitalWrite(d, Off);
    digitalWrite(e, Off);
    digitalWrite(f, On);//
    digitalWrite(g, On);//
    //    digitalWrite(dp, !isdp);
    break;
    case 5:
    digitalWrite(a, On);//
    digitalWrite(b, Off);
    digitalWrite(c, On);//
    digitalWrite(d, On);//
    digitalWrite(e, Off);
    digitalWrite(f, On);//
    digitalWrite(g, On);//
    //digitalWrite(dp, !isdp);
    break;
    case 6:
    digitalWrite(a, On);//
    digitalWrite(b, Off);
    digitalWrite(c, On);//
    digitalWrite(d, On);//
    digitalWrite(e, On);//
    digitalWrite(f, On);//
    digitalWrite(g, On);//
    //digitalWrite(dp, !isdp);
    break;
    case 7:
    digitalWrite(a, On);
    digitalWrite(b, On);
    digitalWrite(c, On);
    digitalWrite(d, Off);
    digitalWrite(e, Off);
    digitalWrite(f, Off);
    digitalWrite(g, Off);
    //    digitalWrite(dp, !isdp);
    break;
    case 8:
    digitalWrite(a, On);
    digitalWrite(b, On);
    digitalWrite(c, On);
    digitalWrite(d, On);
    digitalWrite(e, On);
    digitalWrite(f, On);
    digitalWrite(g, On);
    //digitalWrite(dp, !isdp);
    break;
    case 9:
    digitalWrite(a, On);
    digitalWrite(b, On);
    digitalWrite(c, On);
    digitalWrite(d, On);
    digitalWrite(e, Off);
    digitalWrite(f, On);
    digitalWrite(g, On);
    //digitalWrite(dp, !isdp);
    break;
  }
  

}

void PrintText(int fist,int second,int third,int fourth,bool dp1,bool dp2,bool dp3,bool dp4){
  Symbol(fourth,dp1,5);
  digitalWrite(5, HIGH);
      digitalWrite(5, LOW);

  Symbol(third,dp2,2);

  digitalWrite(6, HIGH);
      digitalWrite(6, LOW);

  Symbol(second,dp3,3);

  digitalWrite(3, HIGH);
      digitalWrite(3, LOW);

  Symbol(fist,dp4,4);

  digitalWrite(4, HIGH);
      digitalWrite(4, LOW);

}
void loop() {
  PrintText(num4,num3,num2,num1,false,false,false,false);
}
void interrupt(){
  static unsigned long last_time=0;
  unsigned long time = millis();
  if (time-last_time>200){
    num1++;
    if (num1==10){
      num1=0;
      num2++;
      if (num2==10){
        num2=0;
        num3++;
          if (num3==10){
            num3=0;
            num4++;
            if (num4==10){
              num4=0;
            }
          }
        
      }
    }
  }
  last_time=time;
}