Arduino Multiplexing 7x7 matrix

alright, I built a 7x7 matrix recently. I used 1- 74HC595 shift register and 7- 2n2222 NPN transistors.

I light up a led for 2 milliseconds, and my code works well and multiplexing works. The problem comes when I use the Serial to read incoming char array and convert it to a byte then do the work.

I use a time and the interval is 1ms. no matter what I do, I can clearly see lights flicker when I feed data from my PC to arduino using this code. I decreased the timer interval to 1ms and in arduino code the time that a led lit for is 2ms. However I only see flickering when only while I’m using serial data. If I were to put some multiplexing in arduino code, it works well without any flickering…Is there any fix to this? I use 115200 as baudrate

First char defines the which row to power-up. In arduino code, inChar[0] is always set to be ‘1’

Arduino Code,

//Pin connected to ST_CP of 74HC595
int latchPin = 10;
//Pin connected to SH_CP of 74HC595
int clockPin = 11;
////Pin connected to DS of 74HC595
int dataPin = 12;

void setup() {
  //set pins to output so you can control the shift register
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
  Serial.begin(115200);
}
int i = 0;
byte b = 0;
char rowa;
char inChar[8];

void loop() {
    while(Serial.available() > 0){
      if(i==0){
        rowa = Serial.read();
      }else{
        inChar[i] = Serial.read();
      }
      i++;
    }
    if(i == 8){
      inChar[0] = '1';
      b = GetBitArrayAsByte(inChar);
      Lit(b,rowa-48,2);
      i=0;
    }
}

char GetBitArrayAsByte(const char inputArray[8])
{
    unsigned char linebyte = 0;
    for (int i = 7, j = 0; j < 8; --i, ++j)
    {
    if (inputArray[j] == '1')
    {
        linebyte |= (1 << i);
    }
    }
    return linebyte;
}

void Lit(byte bot, int row, int t){
  digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, bot);  
    digitalWrite(latchPin, HIGH);
    digitalWrite(row,HIGH);
    delay(t);
    digitalWrite(row,LOW);
}

char getit(const char input[8]){
  char result = 0;
  for(int idx = 0; idx < 8; ++idx){
    result |= (input[7-idx] < idx);
  }
  return result;
}

void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
  int i=0;
  int pinState;
  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, OUTPUT);

  digitalWrite(myDataPin, 0);
  digitalWrite(myClockPin, 0);

  for (i=7; i>=0; i--)  {
    digitalWrite(myClockPin, 0);

    if ( myDataOut & (1<<i) ) {
      pinState= 1;
    }
    else {  
      pinState= 0;
    }

    digitalWrite(myDataPin, pinState);
    digitalWrite(myClockPin, 1);
    digitalWrite(myDataPin, 0);
  }

  
  digitalWrite(myClockPin, 0);
}

C# code,

private void button1_Click(object sender, EventArgs e)
        {
            port = new SerialPort("COM3", 115200);
            port.Open();
            timer1.Enabled = true;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (port.IsOpen)
            {
                char[] bits = { '6', '1', '1', '1', '1', '1', '1', '1' };
                port.Write(bits, 0, bits.Length);
            }
        }

You have some kind of timing issue, which requires seeing the entire sketch in one piece to understand.

aarg:
You have some kind of timing issue, which requires seeing the entire sketch in one piece to understand.

alright, I posted my whole code

bump....anyone knows what is wrong with this?

Scattered:
bump....anyone knows what is wrong with this?

You removed your Serial code from the loop. Didn't you want to receive input?

aarg:
You removed your Serial code from the loop. Didn't you want to receive input?

I'm sorry for the mess. I had pasted the wrong code for loop function. I have corrected it now. please see it

Ok, I found out the problem. the problem lies within the baud rate, increased baud rate do the job, but still has some little flickering that occurs in few seconds interval. I'm now using 2Mbps baud rate