X2 Pushbuttons

Hi,

I have not been able to get the push buttons to work correctly on my X2. The example button project works fine, but if I copy and paste that code into my project (e.g. to wait for BUTTON_A), it will not work. I have the same include files.

This is the code I am trying to use:

unsigned char wait_for_button_and_beep()
{
	unsigned char button = wait_for_button_press(ANY_BUTTON);
	
	if(button & TOP_BUTTON)
	{
		play_from_program_space(beep_button_top);
	}
	else if(button & MIDDLE_BUTTON)
	{
		play_from_program_space(beep_button_middle);
	}
	else
	{
		play_from_program_space(beep_button_bottom);
	}

	wait_for_button_release(button);
	return button;
}

Does anyone have some working sample code that will wait for a single button press on the X2? I’d like to try it in my project to see if it works. Or could anyone explain how the orangutan library deals with button presses and what I need to do to wait for one?

Thank you,

Ryan

Hello, Ryan.

Can you please post the full code for the simplest program that demonstrates the problem, and tell us exactly what happens when you run the code (i.e. how is it not working?)?

- Ben

Hello.

Do you have one of the newer Orangutan X2s with an ATmega1284P? If so, you need to make sure to link with the libpololu_atmega1284p_x2.a library and define the preprocessor macro _X2_1284 in your project configuration.

–David

David,

How do you properly define the preprocessor macro for the X2? I have the library included already.

Thanks!

Ryan

Please see the “Using the Pololu AVR Library for your own projects” section of the Pololu AVR C/C++ Library User’s Guide. It’s at the bottom and there is a screenshot.

–David