reading portD as binary value


greetings,

i attempting read value of 3 hall effect sensors simutaniously using port manipulation.  the hall effect sensors attached pins 5, 6, , 7 (portd).  
code: [select]

#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 code runs not 8 bit representation of portd rather 1 or 0.  is variable halld reading binary number?

is there (correct) way read portx , binary number in variable?

thanks!

try changing:

code: [select]
halld = portd & b11100000;  //only interested in 5,6,7


to:

code: [select]
halld = pind & b11100000;  //only interested in 5,6,7


here reference section on direct port access:
http://www.arduino.cc/en/reference/portmanipulation

basically reading portd reads contents of output data register, reading pind reads actual input pins of port d.

lefty


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > reading portD as binary value


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums