Pushbutton programming?

Hi,

i try to program an interface with several pushbutton triggered functions. there is the main loop, and inside there should be another condition with a lot of action (i reduced it in my code to “play_frequency(2000, 60, 13);”), triggered by the TOP_BUTTON. but before this action starts, i want to trigger another small function by a pushbutton. this function behaves correct, but the “TOP_BUTTON” - triggered function does not start. can you have a look at my source code?
thanks!

int main()
{

while (1){

if (get_single_debounced_button_press(ANY_BUTTON) == MIDDLE_BUTTON)  
play_frequency(8000, 60, 13);

if (get_single_debounced_button_release(ANY_BUTTON) == MIDDLE_BUTTON)
play_frequency(4000, 60, 13);
}


if (get_single_debounced_button_press(ANY_BUTTON) == TOP_BUTTON){
play_frequency(2000, 60, 13);
}
}

Hello.

Please make sure you mention which product you are using! I’m guessing from your code that it is one of our Orangutan robot controllers?

I think the reason you are never seeing the top button action is because you are capturing the button press with your initial check. What happens if you change your code to:

int main()
{

  while (1){

  unsigned char button_press = get_single_debounced_button_press(ANY_BUTTON);
  if (button_press == MIDDLE_BUTTON)  
    play_frequency(8000, 60, 13);
  else if (button_press = TOP_BUTTON)
    play_frequency(2000, 60, 13);

  if (get_single_debounced_button_release(ANY_BUTTON) == MIDDLE_BUTTON)
    play_frequency(4000, 60, 13);
  }
}

- Ben