I'm trying to manipulate the ports of Arduino using C code. I have attached an LED to pin 8 and a tact switch to pin 13 (with a pull down resistor). The code works fine, and the results are printed on the screen. So, when the button is pressed, the byte PINB & (1 << PB5)
equals 32, or 0b00100000
.
However, if I try to use
if( PINB &(1<<PB5) == 32){
or
if( PINB &(1<<PB5) == 0b00100000){
the LED doesn't respond.
Here's the full code:
void setup() {
DDRB |= 0b00011111;
Serial.begin(9600);
}
void loop() {
Serial.print("PINB &(1<<PB5)");
Serial.println(PINB &(1<<PB5));
if( PINB &(1<<PB5) ){
PORTB |= (1<<PB0);
}
else{
PORTB &= ~(1<<PB0);
}
}
What am I missing?
== ...
?