// By Nissanka MD COTM

  #define pinDp 2
  #define pinC  3
  #define pinD  4
  #define pinE  5
  #define pinG  6
  #define pinF  7
  #define pinA  8
  #define pinB  9
  #define pinComDig1  12
  #define pinComDig2  13

  bool commonCathod = true;
  bool enableDisplay;
  bool disableDisplay;

  bool A;
  bool B;
  bool C;
  bool D;
  bool E;
  bool F;
  bool G;
  bool Dp;
  bool ComDig1;
  bool ComDig2;
  

  int delayDigitDisplay = 300;

  void writeDisplay(){
    digitalWrite(pinComDig1,commonCathod);
    digitalWrite(pinComDig2,commonCathod);
    digitalWrite(pinA,A);
    digitalWrite(pinB,B);
    digitalWrite(pinC,C);
    digitalWrite(pinD,D);
    digitalWrite(pinE,E);
    digitalWrite(pinF,F);
    digitalWrite(pinG,G);
    digitalWrite(pinDp,Dp);
    digitalWrite(pinComDig1,ComDig1);
    digitalWrite(pinComDig2,ComDig2);

  }


  void allOff(){
    A=LOW;
    B=LOW;
    C=LOW;
    D=LOW;
    E=LOW;
    F=LOW;
    G=LOW;
    Dp=LOW;
    //writeDisplay();
  }

  void allOn(){
    A=HIGH;
    B=HIGH;
    C=HIGH;
    D=HIGH;
    E=HIGH;
    F=HIGH;
    G=HIGH;
    //Dp=HIGH;
    //writeDisplay();
  }

  void allOnWrite(){
    allOn();

  }

  void allOffWrite(){
    allOff();

  }

  void n1(){
    allOff();
    B=HIGH;
    C=HIGH;

  }

  void n2(){
    allOn();
    C=LOW;
    F=LOW;

  }

  void n3(){
    allOn();
    E=LOW;
    F=LOW;

  }

  void n4(){
    allOn();
    A=LOW;
    D=LOW;
    E=LOW;

  }

  void n5(){
    allOn();
    B=LOW;
    E=LOW;

  }

  void n6(){
    allOn();
    B=LOW;

  }

  void n7(){
    allOff();
    A=HIGH;
    B=HIGH;
    C=HIGH;

  }

  void n8(){
    allOn();

  }

  void n9(){
    allOn();
    E=LOW;

  }

  void n0(){
    allOn();
    G=LOW;

  }

  void Err(){
    allOn();
    B=LOW;
    C=LOW;

  }



  void displayDigit(int digit){

    allOffWrite();

    switch(digit){
      
      case 0:
        n0();
      break;

      case 1:
        n1();
      break;

      case 2:
        n2();
      break;

      case 3:
        n3();
      break;

      case 4:
        n4();
      break;

      case 5:
        n5();
      break;

      case 6:
        n6();
      break;

      case 7:
        n7();
      break;

      case 8:
        n8();
      break;

      case 9:
        n9();
      break;

      default:
      Err();
      break;

    }

  }

  void displayNumber(int Dig1,int Dig2){

    displayDigit(Dig1);
    ComDig1 = enableDisplay; // on display1
    writeDisplay();
    delay(delayDigitDisplay);
    ComDig1 = disableDisplay; //off display1

    displayDigit(Dig2);
    ComDig2 = enableDisplay; // on display1
    writeDisplay();
    delay(delayDigitDisplay);
    ComDig2 = disableDisplay; //off display1
  

  }
  

  



  void setup() {
  for (int i=2; i<14; i++){
          pinMode(i,OUTPUT);
      }
  enableDisplay = !commonCathod;
  disableDisplay = commonCathod;

  ComDig1 = disableDisplay;
  ComDig2 = disableDisplay;

  }

  void loop() {
    // put your main code here, to run repeatedly:

  displayNumber(2,6);

  }