Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Orangutan SWITCH code


#1

boy, i’m having the hardest time trying to write a simple, simple program just to check whether any of the three switches on the Orangutan is pressed. for example, if i’m interested in checking the status of SW3, shouldn’t the following work?

#define Testbit(x,y) (x&(1<<y)) // Returns 0 if clear, Bit value if set.

void main(void){
	unsigned char button_state;
	while(1){
	DDRB &= ~(1<<PB3);	// set at input
	button_state = Testbit(PORTB,PB3);
	if(button_state){
		beep();
		}
	}
}

#2

Hi,

Try reading PINB instead of PORTB.

- Sean