       0b00000000   // blank
     };
 
-byte control_digit_pins[] = { digit0, digit1, digit2, digit3 };  // pins to turn off-&-on digits
 
 char matrix ()
 {


ISR(TIMER1_COMPA_vect)
{
    if (0 == countdown--) {
        countdown = countdown_base;
    }
}

        digitalWrite(latchPin,LOW);  // [=latch down=]
        shiftOut(dataPin, clockPin, MSBFIRST, (displayDigits[x]));
        digitalWrite(latchPin,HIGH); // [=latch up=]
        if (pulse && mode) {
            if (submode == x) {
                digitalWrite(control_digit_pins[x], LOW); // turn off
            } else {
                digitalWrite(control_digit_pins[x], HIGH); // turn on
            }
        } else {
            digitalWrite(control_digit_pins[x], HIGH); // turn on
        }
        delay(1); // 1 or 2 is ok
    }
    display_off();
}

/* void hex2disp (int param, byte result[4]) { */
/*     int temp = param; */
/*     int mask = 0xF; */
/*     for (int x=0; x<4; x++) { */
/*         result[x] = table[(temp & mask)]; */
/*         temp = temp >> 4; */
/*     } */
/* } */

/* unsigned char hex2bcd (unsigned char x) */
/* { */
/*     unsigned char y; */
/*     y = (x / 10) << 4; */
/*     y = y | (x % 10); */
/*     return (y); */
/* } */

int time_bcd_to_int (byte param[4]) {
    int minute_hi = param[3];
    int minute_lo = param[2];
    int second_hi = param[1];
    int second_lo = param[0];
    int minutes = minute_hi * 10 + minute_lo;
    int seconds = second_hi * 10 + second_lo;
    return minutes * 60 + seconds;
}

void int_to_time_bcd (int param, byte result[4]) {
    int minutes = param / 60;
    int seconds = param % 60;
    int minute_hi = minutes / 10;
    int minute_lo = minutes % 10;
    int second_hi = seconds / 10;
    int second_lo = seconds % 10;
    result[0] = second_lo;
    result[1] = second_hi;
    result[2] = minute_lo;
    result[3] = minute_hi;
}

void time_bcd_to_time_str (byte param[4], byte result[4]) {
    result[0] = table[param[0]];
    result[1] = table[param[1]];
    result[2] = table[param[2]];
    result[3] = table[param[3]];
}


void submode_inc() {
    submode++;
    if (submode > 3) { submode = 3; }
}


void submode_dec() {
    submode--;
    if (submode < 0) { submode = 0; }
}


/* MAIN LOOP */
void loop() {
    /* time cycle */
    unsigned long new_time = millis();
    if ((new_time > (time + 200))) {
        pulse = !pulse;
        time = new_time;
        /* Serial.println(time); */
        char symbol = matrix();
        if ('X' != symbol) {
            Serial.println(symbol);
        }
        byte input = 0xF;
        switch (symbol) {
        case 'C':
            mode = 1;
            submode = 3;
            break;
        case '=':
            mode = 0;
            break;
        case '-':
            submode_inc();
            break;
        case '+':
            submode_dec();
            break;
        case '0':
            input = 0;
        case '1':
            input = 1;
            break;
        case '2':
            input = 2;
            break;
        case '3':
            input = 3;
            break;
        case '4':
            input = 4;
            break;
        case '5':
            input = 5;
            break;
        case '6':
            input = 6;
            break;
        case '7':
            input = 7;
            break;
        case '8':
            input = 8;
            break;
        case '9':
            input = 9;
            break;
        }
        if (mode && (input != 0xF)) {
            time_bcd[submode] = input;
            submode_inc();
            countdown = time_bcd_to_int( time_bcd );
        }
    }
    byte displayDigits[] = { 0b00111111, 0b00111000,
                             0b01110111, 0b01110110 };
    /* time_bcd is a countdown */
    int_to_time_bcd( countdown, time_bcd );
    /* displayDigits is a time_bcd */
    time_bcd_to_time_str( time_bcd, displayDigits );
    /* show DisplayDigits */
    DisplaySegments( displayDigits );

    /* countdown = time_bcd_to_int( time_bcd ); */
}

void setup() {
