Evaulate multiple pin values on a port

Hello,

I want to read the pins 3-7 of portD on the Arduino 328p, then compare them to an array(?) of high/low values for each pin. Depending on what which values are high/low I want execute a procedure. Any clues on how to do this?

Thanks,

-ren

example
uint8_t x = PORTD & B11100100;  // only read pin 7,6,5, and 2

if (x & B1000000) // pin 7 high
if (x & B1000000 == 0) // pin 7 low
if (x & B0100000) // pin 6 high

or 

switch(x)
{
  case B11000000 :  // act if pin 7,6 HIGH and 5,2 LOW
     ...
     break;
  case B10100000:  // act if pin 7, 5 HIGH and 6,2 LOW
    ...
     break;
  // more of the same

  default:  // all other cases
    break;
}

instead of B11100000 one can use hex notation e.g. 0xE0 as this is shorter

furthermore one could pack the bits tightly

uint8_t x = PORTD & B11100100; // only read pin 7,6,5, and 2 uint8_t y = (x& B00000100) >> 2 & x >>4;

y contains now the value of bit 7,6,5,2 in bit position 0,1,2,3 , that makes it usable as index for an array or have a switch statement with consecutive numbers.

hope this get you started, Rob

Rob,

Thanks for the help! I used the tips you listed below to make the compare. I used PIND as opposed to PORTD to read the pin values though.

-ren