Read PORTD as output and show the status in serial monitor

To whom it may concern.

At the moment I am coding a software to simulate 6 light barriers.
Always 3 lightbarriers are LOW or HIGH at the same time or all 6 are LOW or HIGH.
To give the Test Device the needed signal I am using PORTD
The digital outputs are changig their status in a specified sequenz.
Please see a part of the code above:

#include <avr/io.h>

void setup()
{
Serial.begin(9600);
DDRD = DDRD | B11111100; // D7;D6;D5;D4;D3;D2; als Ausgänge D1;D0 als
// Eingang
}

//
void loop()
{

PORTD = B00000000; // Contact -2 D7 bis D2 auf LOW für 348ms
delay(348);

PORTD = B11111100; // Flight -2 Pin D7 bis D2 auf HIGH für 1700ms
delay(1700);

PORTD = B00000000; // Contact -1 D7 bis D2 auf LOW für 358ms
delay(358);
PORTD = B11111100; // Flight -1 D7 bis D2 auf HIGH für 1800ms
delay(1800);

PORTD = B00000000; // Contact 0 D7 bis D2 auf LOW für 353ms
delay(353);

PORTD = B11111100; // Flight 0 D7 bis D2 auf HIGH für 1740ms
delay(1740);
PORTD = B00011100; // Flight 0 D7 bis D5 auf LOW & D4 bis D2 auf HIGH für
delay(10); // weitere 10ms

and so on…

Now I want to show the sequenz in a serial monitor. It also would be very nice to check if the outputs are changig their status in the defined time.

I thought about something like that:

11111100 – 1740ms
00011100 – 10ms
.
.
.

Can anybody help to achieve that goal??

I am pleased about every support!

Best regards,

curverer

Try this to print the first 6 bits of PORTD, don't understand your other request.

for(byte j = 7;j > 1;j--)
  Serial.print(PIND & bit(j) ? 1 : 0);
Serial.println();

Read OUTPUT pins? Use a variable to set them and "read" that.

Would you like to get rid of the delay code so you can update display, read buttons and have your port writes happen on time all at once, not like chess but like RTS instead?

Thanks for your answers!
The next step is to show, how long the Output are staying in their current state.
I need to show someone, for how long the outputs are LOW or HIGH.
Best regards,
curverer

The next step is to show, how long the Output are staying in their current state.

Save the time from millis() when an output changes state, then next time it changes state subtract the first time from the current time.

curverer:
Thanks for your answers!
The next step is to show, how long the Output are staying in their current state.

I need to show someone, for how long the outputs are LOW or HIGH.
Best regards,
curverer

The pin will deliver power until your sketch turns it off or it doesn't burn up. Your circuit is supposed to keep the pin safe.

You can supply 5V through 20K to 50K internal chip resistor and read the pin using pinMode( pin, INPUT_PULLUP ).

You can switch the pin mode from OUTPUT to INPUT but it will go LOW unless the wire to the pin supplies current.

Maybe you could add circuit to let you read the state of the wire on another pin as INPUT.
Or connect a led to light when the wire is HIGH just to show the state.
But I don't know what either would do to your original use of the pin.

Reading a pin set to OUTPUT will only tell you what it is set to, not whether the wire is LOW or HIGH.