Printing Status of PORTB when using port manipulation

Hello,

I am trying to read several signals at the same time using Port Manipulation. However I would like to print the status of the port register to the serial monitor. Below is the code I am currently trying to implement.

void setup() {
Serial.begin(9600);
PORTB = B00000000;

}

void loop() {
Serial.print(PORTB,5);
}

Serial.print(PINB, BIN);DDRx writes pins as I or O, PORTx writes pins as HIGH or LOW, PINx reads state of pins.

rdk9000:
Hello,

I am trying to read several signals at the same time using Port Manipulation. However I would like to print the status of the port register to the serial monitor. Below is the code I am currently trying to implement.

void setup() {
Serial.begin(9600);
PORTB = B00000000;

}

void loop() {
Serial.print(PORTB,5);
}

Why would you want to print anything radix 5?

Did you, perhaps, want the state of bit 5?

void loop() {
  Serial.print(!!(PORTB & _BV(5)));
}

_BV(5) means "bit 5" or 0x20.
The '&' operator (bitwise AND) masks off the unwanted bits leaving 0x00 if but 5 is 0 or 0x20 if bit 5 is 1.
When used as the argument to '!' operator (boolean invert) the integer value 0x00 gets reduced to a boolean value of 'false' and the 0x20 gets reduced to a boolean value of 'true' before being inverted which turns 0x00 into 'true' and 0x20 into 'false'.
The second '!' un-does the inversion but keeps the reduction o boolean.
The resulting boolean value gets promoted to an integer value of 0 (false) or 1 (true).

rdk9000:
Hello,

I am trying to read several signals at the same time using Port Manipulation. However I would like to print the status of the port register to the serial monitor. Below is the code I am currently trying to implement.

void setup() {
Serial.begin(9600);
PORTB = B00000000;

}

void loop() {
Serial.print(PORTB,5);
}

PORTB should stay the same as you wrote it in setup(), or B00000000, because the port is by default configured as an INPUT port. The PORTB instruction in setup doesn't really accomplish anything, if any of the bits were set to 1 instead of 0 you would be turning on the internal pullup resistor. As the previous poster pointed out, to read the inputs you use PINB. Unfortunately the print() instruction suppresses leading zeros, which can make the output format a bit difficult to read for binary or hex data, if you want to see the leading zeros the input port can be read into a variable, then printed out a bit at a time.