const int button1 = A0;
const int button2 = A1;
const int button3 = A2;
const int button4 = A3;

const int digits[11] = {
  0b0111111, //0
  0b0000110, //1
  0b1011011, //2
  0b1001111, //3
  0b1100110, //4
  0b1101101, //5
  0b1111101, //6
  0b0000111, //7
  0b1111111, //8
  0b1101111, //9
  0b0000000, //blank
};

//common anode 
//const int digits[11] = {
// 0b1000000, //0
// 0b1111001, //1
// 0b0100100, //2
// 0b0110000, //3
// 0b0011001, //4
// 0b0010010, //5
// 0b0000010, //6
// 0b1111000, //7
// 0b0000000, //8
// 0b0010000, //9
// 0b1111111, //blank
//};

int disp1 = 0;
int disp2 = 0;
int blinks = 0;

bool seq1 = false;
bool seq2 = false;
bool seq3 = false;
bool seq4 = false;

const long interval = 100;
unsigned long previousMillis = 0;


void setup(){
  for (int i = 0; i <= 13; i++)
    pinMode(i, OUTPUT);
  
  for (int buttons = A0; buttons <=A3; buttons++) {
    pinMode(buttons, INPUT_PULLUP);

  }
  
  
  for(int i = 0, a = 0; i < 7; i++, a++){ 
    digitalWrite(i, bitRead(digits[0], a));
  }
  
  for(int j = 7, b = 0; j <= 13; j++, b++){
    digitalWrite(j, bitRead(digits[0], b));
  }
}

void loop(){
  unsigned long currentMillis = millis();
  
  if(digitalRead(button1) == LOW){
    seq1 = true;
    seq2 = false;
    seq3 = false;
    seq4 = false;
    disp1 = 9;
    disp2 = 9;
  }
  
  else if(digitalRead(button2) == LOW){
    seq1 = false;
    seq2 = true;
    seq3 = false;
    seq4 = false;
    disp1 = 0;
    disp2 = 0;
  }
  
  else if(digitalRead(button3) == LOW){
    seq1 = false;
    seq2 = false;
    seq3 = true;
    seq4 = false;
    disp1 = 9;
    disp2 = 0;
  }
  
  else if(digitalRead(button4) == LOW){
    seq1 = false;
    seq2 = false;
    seq3 = false;
    for (int inf = 0; inf <= 500; inf++) {
    seq4 = true;
    blinks = 0;
    }
  }
  
  if(seq1) { //button1
    if(currentMillis - previousMillis > interval) {
      
     resetSSD();
      displayOnes(disp2);
      displayTens(disp1);
      
      disp2--;
      if(disp2 < 0) {
        disp2 = 9;
        
      disp1--;
      if(disp1 < 0)
        disp1 = 9;
      }
      previousMillis = currentMillis;
    }
  }
  
  else if(seq2){ //button2
    if(currentMillis - previousMillis > interval) {
      
      resetSSD();
      displayOnes(disp2);
      displayTens(disp1);
      
      disp2++;
      if(disp2 > 9) {
        disp2 = 0;
        
      disp1++;
      if(disp1 > 9)
        disp1 = 0;
      }
      previousMillis = currentMillis;
    }
  }
  
  else if(seq3){ //button3
    if(currentMillis - previousMillis > interval*3) {
      
      resetSSD();
      displayOnes(disp2);
      displayTens(disp1);
      
      disp2++;
      if(disp2 > 9) 
        disp2 = 0;
        
      disp1--;
      if(disp1 < 0)
        disp1 = 9;

      previousMillis = currentMillis;
     }
  }
  
  else if(seq4){ 
    if(blinks < 10) {

      if(currentMillis - previousMillis > interval)
        turnOff();
        
      if(currentMillis - previousMillis > interval*2) {
        resetSSD();
        previousMillis = currentMillis;
        blinks++;
      }
    }
  }
}

void displayOnes(const int x){
  int pin2, l;
  
  for (pin2 = 7, l = 0; pin2 <= 13; pin2++, l++) {
    digitalWrite(pin2, bitRead(digits[x], l));
  }
}
  
void displayTens(const int y){
  int pin1, m;
  
  for (pin1 = 0, m = 0; pin1 < 7; pin1++, m++){
    digitalWrite(pin1, bitRead(digits[y], m));
  }
}

void resetSSD(){
  int pins, n;
  
  for (pins = 0, n = 0;pins < 7; pins++, n++){
    digitalWrite(pins, bitRead(digits[0], n));
  }
  
  for(pins = 7, n = 0;pins <= 13;pins++, n++){
    digitalWrite(pins, bitRead(digits[0], n));
  }
}

void turnOff(){
  int pins, o;
  for (pins = 0, o = 0; pins < 7; pins++, o++){
    digitalWrite(pins, bitRead(digits[11], o));
  }
  
  for (pins = 7, o = 0; pins <= 13; pins++, o++){
    digitalWrite(pins, bitRead(digits[11], o));
  }
}
$abcdeabcde151015202530354045505560fghijfghij