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).
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!
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:
to:
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
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
Post a Comment