I've been sitting here scratching my head for a while now. I was trying to read pin 3 in PORTD with binary operators instead of with digitalRead. So, here is a working example using digitalRead (pin 3 is physically high in both cases):
Now to use the I/O pins as inputs. Again, it is very simple to do so. In void setup(), we use
DDRy = Bxxxxxxxx
where y is the register type (B/C/D) and xxxxxxxx are eight bits that determine if a pin is to be an input or output. Use 0 for input. The LSB (least-significant bit [the one on the right!]) is the lowest pin number for that register. Next, to read the status of the pins we simply read the byte:
PINy
where y is the register type (B/C/D). So if you were using port B as inputs, and digital pins 8~10 were high, and 11~13 were low, PINB would be equal to B00000111. Really, that’s it!