6.h. Orangutan Pushbutton Interface Functions

Overview

This library allows you to easily interface with the three user pushbuttons on the 3pi Robot and the Orangutan LV-168 by either polling for the state of specific buttons or by waiting for press/release events on specifiable buttons. 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 8 of the Pololu AVR Library Command Reference.

Usage Examples

This library comes with two examples 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
 *
 * This example program is intended for use on the Orangutan LV-168.
 * It 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/6.h
 * 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);
  }
}