3.g. Orangutan Pushbutton Interface Functions

Overview

This library allows you to easily interface with the three user pushbuttons on the 3pi robot, Orangutan SV, Orangutan SVP, and Orangutan LV-168 by either polling for the state of specific buttons or by waiting for press/release events on specifiable buttons. The first time any function in this section is called, the function will initialize all the button I/O pins to be inputs and enable their internal pull-up resistors. The wait_for_button_…() methods in this library automatically take care of button debouncing.

C++ users: See Section 5.f of Programming Orangutans from the Arduino Environment for examples of this class in the Arduino environment, which is almost identical to C++.

Complete documentation of these functions can be found in Section 9 of the Pololu AVR Library Command Reference.

This library comes with an example program in libpololu-avr\examples.

1. pushbuttons1

Demonstrates interfacing with the user pushbuttons. It will wait for you to push either the top button or the bottom button, at which point it will display on the LCD which button was pressed. It will also detect when that button is subsequently released and display that to the LCD.

#include <pololu/orangutan.h>

/*
 * OrangutanPushbuttonExample: for the Orangutan LV-168,
 *   Orangutan SV-xx8, Orangutan SVP, and 3pi robot
 *
 * This example uses the OrangutanPushbuttons library to detect user
 * input from the pushbuttons, and it uses the OrangutanLCD library to
 * display feedback on the LCD.
 *
 * http://www.pololu.com/docs/0J20
 * http://www.pololu.com
 * http://forum.pololu.com
 */

int main()
{
  while(1)
  {
    clear();
    print("Waiting");
    
    // wait for either the top or bottom buttons to be pressed
    // store the value of the pressed button in the variable 'button'
    unsigned char button = wait_for_button_press(TOP_BUTTON | BOTTOM_BUTTON);
    clear();
    if (button == TOP_BUTTON)     // display the button that was pressed
      print("top down");
    else
      print("bot down");
    wait_for_button_release(button);  // wait for that button to be released
    clear();
    print("released");      // display that the button was released
    delay_ms(1000);
  }
}