Support » Programming Orangutans and the 3pi Robot from the Arduino Environment » 5. Arduino Libraries for the Orangutan and 3pi Robot »
5.f. OrangutanPushbuttons - Pushbutton Interface Library
Overview
This library allows you to easily interface with the three user pushbuttons on the 3pi robot, Orangutan SV-xx8, and Orangutan LV-168 by either polling for the state of specific buttons or by waiting for press/release events on specifiable buttons. The waitFor____() methods in this library automatically take care of button debouncing.
You do not need to initialize your OrangutanPushbuttons object before use. All initialization is performed automatically when needed.
All of the methods in this class are static; you should never have more than one instance of an OrangutanPushbuttons object in your sketch.
OrangutanPushbuttons Methods
Complete documentation of this library’s methods can be found in Section 9 of the Pololu AVR Library Command Reference.
Usage Examples
This library comes with an example sketch that you can load by going to File > Examples > OrangutanPushbuttons.
1. OrangutanPushbuttonExample
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 <OrangutanLCD.h> #include <OrangutanPushbuttons.h> /* * OrangutanPushbuttonExample: for the 3pi robot, Orangutan LV-168, * and Orangutan SV-xx8 * * 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. */ OrangutanPushbuttons buttons; OrangutanLCD lcd; void setup() // run once, when the sketch starts { } void loop() // run over and over again { lcd.clear(); lcd.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 = buttons.waitForPress(TOP_BUTTON | BOTTOM_BUTTON); lcd.clear(); if (button == TOP_BUTTON) // display the button that was pressed lcd.print("top down"); else lcd.print("bot down"); buttons.waitForRelease(button); // wait for that button to be released lcd.clear(); lcd.print("released"); // display that the button was released delay(1000); }