I'm trying to manipulate the ports of Arduino using C code. I have attached an LED in Pin8 and a tact switch in Pin13 (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 to 32, or else 0b00100000.
But 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?
Thank you
== ...
? – Peter R. Bloomfield♦ yesterday