read and show on serial monitor not synchronized.

Hi all,
I pretend to use Arduino as a logic analyzer. Now, I trying to read PORTB (pin8~pin13) and then showing on serial monitor.
But the data is not synchronized.
(For example, I make pin12 connected to 5V and then swap with 0V. There was a delay between swapping 5V with 0V.
If I swapped to 0V, the serial monitor still show pin12 is HIGH. After few seconds, it shows LOW. )
What’s wrong with it?

byte a;


void setup() {
Serial.begin(115200);

  DDRB = B00000000;

}

// the loop function runs over and over again forever
void loop() {

 a=PINB;
Serial.println(a,BIN);

}

arduino_logic_detect.ino (179 Bytes)

You are printing much too fast for the Serial connection. Try adding delay(200); as the last thing in loop().

...R