reading portD as binary value

Greetings,

I am attempting to read the value of 3 hall effect sensors simutaniously using port manipulation. The hall effect sensors are attached to pins 5, 6, and 7 (portD).

#define HALL1 7
#define HALL2 6
#define HALL3 5

int hallSensors[3];
int hallD = B00000000;
int prevhallD = B00000000;
void setup()
{
Serial.begin(9600);
pinMode(HALL1, INPUT);
pinMode(HALL2, INPUT);
pinMode(HALL3, INPUT);

}

void loop(){
  
hallD = PORTD & B11100000;  //only interested in 5,6,7 
Serial.println (hallD, BIN);
delay (500);
if (hallD != prevhallD){  //etc.....

When the code runs I do not get an 8 bit representation of PORTD rather I get a 1 or 0. is my variable hallD actually reading the binary number?

is there another (correct) way to read from PORTX and get a binary number in a variable?

Thanks!

Try changing:

hallD = PORTD & B11100000;  //only interested in 5,6,7

to:

hallD = PIND & B11100000;  //only interested in 5,6,7

Here is reference section on direct port access:

Basically reading PORTD reads back the contents of the output data register, where as reading PIND reads the actual input pins of port D.

Lefty