Trying to read PORT D

I'm trying to read the PORTD using the PIND command, but always keep getting TX button blinking... I thought the PIND command only read state of the PIN, and doesn't change the state of the PIN. Why ?

const int SwPA = 2; // Switch at PORTD 2 .. Connected to LOW
const int SwMA = 3; // Switch at PORTD 2 .. Connected to LOW
int buttonPressed; 

void setup(){
  Serial.begin(9600);
  pinMode(SwPA, INPUT);
  pinMode(SwMA, INPUT); // Set as input
  digitalWrite(SwPA, HIGH); // activate internal pull-up
  digitalWrite(SwMA, HIGH); // activate internal pull-up
}

void loop(){
  buttonPressed = PIND & B00001100; // Read only the Digital Pin 2 and 3
  Serial.println(buttonPressed);
  delay(1000);
}

Sugengz: I'm trying to read the PORTD using the PIND command, but always keep getting TX button blinking... I thought the PIND command only read state of the PIN, and doesn't change the state of the PIN. Why ?

...
  digitalWrite(SwPA, HIGH); // activate internal pull-up
  digitalWrite(SwMA, HIGH); // activate internal pull-up
...

What state is reported?

Why do you activate the interal pullups? (just curious)

Do you mean "TX led blinking", isn't that just the serial sending back the print data?

Sugengz:
I’m trying to read the PORTD using the PIND command, but always keep getting TX button blinking…
I thought the PIND command only read state of the PIN, and doesn’t change the state of the PIN.
Why ?

The Tx button (button?) - the one that lights up when you do a Serial.println?

I'm trying to read the PORTD using the PIND command

Command?

but always keep getting TX button blinking

Try to get the terminology right. The thing that blinks is a LED, not a button.

Why aren't you using digitalRead? That is simpler to use and works over more platforms.

ofransen:

Sugengz: I'm trying to read the PORTD using the PIND command, but always keep getting TX button blinking... I thought the PIND command only read state of the PIN, and doesn't change the state of the PIN. Why ?

...
  digitalWrite(SwPA, HIGH); // activate internal pull-up
  digitalWrite(SwMA, HIGH); // activate internal pull-up
...

What state is reported?

Why do you activate the interal pullups? (just curious)

Do you mean "TX led blinking", isn't that just the serial sending back the print data?

Because I connect the other end of the switch to LOW.... So when the switch ON, it will connect to LOW....

So TX led blinking because of Serial.println() command ?

Sugengz: So TX led blinking because of Serial.println() command ?

Yes, if you do serial prints, the Tx LED will blink.

[quote author=Nick Gammon link=topic=78728.msg594392#msg594392 date=1321083616] Try to get the terminology right. The thing that blinks is a LED, not a button. Why aren't you using digitalRead? That is simpler to use and works over more platforms. [/quote]

Yes, it's supposed TX Led, not a button (thanks for the correction) .

I'm trying to read the digital pin 2 until 7 as a binary combination, and read it all in a single line of instruction, not pin by pin. (this case I tried to do digital pin 2 and 3 only).

Can we use digitalRead to read digital pin 2 until 7 in a single line of instruction?

Thank you

No. Your technique of testing PORTD is the way to go for that. Timing must be pretty critical, right?

But don't be surprised if the Tx LED lights up, if you are sending serial data.