LED matrix - one by one LED not really working

I’m using 4x8 LED matrix using ULN2803. This is the code I use for debugging purposes and also to turn one LED on at the time:

oneByOneLED() {

    for (int i=0; i<4; i++) {

     switch (i) {

     case 0:
     pinMode(ledRowArray[1], INPUT);
     digitalWrite(ledRowArray[1], LOW);

     pinMode(ledRowArray[2], INPUT);
     digitalWrite(ledRowArray[2], LOW);

     pinMode(ledRowArray[3], INPUT);
     digitalWrite(ledRowArray[3], LOW);

     break;


     case 1:
     pinMode(ledRowArray[0], INPUT);
     digitalWrite(ledRowArray[0], LOW);

     pinMode(ledRowArray[2], INPUT);
     digitalWrite(ledRowArray[2], LOW);

     pinMode(ledRowArray[3], INPUT);
     digitalWrite(ledRowArray[3], LOW);

     break;


     case 2:
     pinMode(ledRowArray[0], INPUT);
     digitalWrite(ledRowArray[0], LOW);

     pinMode(ledRowArray[1], INPUT);
     digitalWrite(ledRowArray[1], LOW);

     pinMode(ledRowArray[3], INPUT);
     digitalWrite(ledRowArray[3], LOW);

     break;


     case 3:
     pinMode(ledRowArray[0], INPUT);
     digitalWrite(ledRowArray[0], LOW);

     pinMode(ledRowArray[1], INPUT);
     digitalWrite(ledRowArray[1], LOW);

     pinMode(ledRowArray[2], INPUT);
     digitalWrite(ledRowArray[2], LOW);

     break;

     default:
     break;

     }

        pinMode(ledRowArray[i], OUTPUT);
        digitalWrite(ledRowArray[i], HIGH);


    for (int j=0; j<NUMBER_OF_COLUMNS; j++) {


    digitalWrite(SHARED_PIN_1, bitRead(j,2));
    digitalWrite(SHARED_PIN_2, bitRead(j,1));
    digitalWrite(SHARED_PIN_3, bitRead(j,0));

    delay(5000);

    Serial.print("Row: ");
    Serial.print(i+1);
    Serial.print("\n");
    Serial.print("Column: ");
    Serial.print(j+1);
    Serial.print("\n");
    Serial.print("LED number: ");
    Serial.print(j+NUMBER_OF_COLUMNS*i);
    Serial.print("\n\n");


    }

    }



}

ledRowArray is the array of 4 output pins:

    ledRowArray[0] = LED_ROW_PIN_1;
    ledRowArray[1] = LED_ROW_PIN_2;
    ledRowArray[2] = LED_ROW_PIN_3;
    ledRowArray[3] = LED_ROW_PIN_4;

Now at this point everything works fine. I learned today that unless I set unused row pins as inputs and write LOW to them there is a possibility to turn on multiple leds on using only one row pin and one column pin. Why is that happening?

I’ve also got array of boolean values indicating state of LED. I wrote a simple function to test this:

setLEDstate(int led, boolean state) {


    ledState[led] = state;

}

This is the part in which I cycle columns:

nextColumn() {

    for (int i=0; i<NUMBER_OF_COLUMNS; i++) {

    digitalWrite(SHARED_PIN_1, bitRead(i,2));
    digitalWrite(SHARED_PIN_2, bitRead(i,1));
    digitalWrite(SHARED_PIN_3, bitRead(i,0));

    checkLEDs(i);

    }

}

The check LEDs functions looks like this:

checkLEDs(int column) {


    for (int i=0; i<4; i++) {

    if (ledState[i*NUMBER_OF_COLUMNS+column] == true)  {

        pinMode(ledRowArray[i], OUTPUT);
        digitalWrite(ledRowArray[i], HIGH);


    }   else {

        pinMode(ledRowArray[i], INPUT);
        digitalWrite(ledRowArray[i], LOW);

        }

    }

}

In loop function I only call the nextColumn() function and in setup I call this:

setLEDstate(0, true);

Which does cause LED 0 to turn on which is of course on first (0) column but it does also turn LED 30 on column 6/row 3.

It’s really unclear to me why when using oneByOneLED function everything works fine and when using the latter method there are multiple LEDs on.