I'm learning about accessing ports directly on the ATMEGA 328 using an Arduino Uno. The program sets up pin 13 as an output and pin 2 as an input. I then enable the pull up resistor on pin 2.
I read Pin 2 and set the LED high or low depending on if pin 2 is high or low.
Why is it that I cannot seem to use == HIGH in my if statement instead of != LOW?
void setup() {
MCUCR &= ~(1 << 4); //disables pull-up disable (redundant as default is off)
DDRB |= (1 << 5); //sets pin 13 (B5 on ATMEGA 328) as output
DDRD &= ~(1 << 2); //sets pin 2 (D2 on ATMEGA 328) as input (redundant as default is input)
PORTD |= (1 << 2); //since it's an input sets pull-up resistor ON
PORTB &= ~(1 << 5); //sets pin 13 (B5 on ATMEGA 328) as LOW
}
void loop() {
if ((PIND & (1 << 2)) != LOW) PORTB |= (1 << 5); //sets pin 13 (B5 on ATMEGA 328) as HIGH
else PORTB &= ~(1 << 5); //sets pin 13 (B5 on ATMEGA 328) as LOW
delay(100);
}