diff --git a/README.md b/README.md index c9546f4..0031bb9 100644 --- a/README.md +++ b/README.md @@ -2,30 +2,175 @@ Debouncing library for Arduino and Wiring by Thomas Ouellet Fredericks with contributions from: Eric Lowry, Jim Schimpf, Tom Harkaway, Joachim Krüger and MrGradgrind. -More about debouncing: http://en.wikipedia.org/wiki/Debounce#Contact_bounce +Basically, the mechanical part of buttons and switches vibrate slightly when closed or opened causing multiple undesired false states (similar to noise). This library filters out these undesired state changes. More about debouncing: http://en.wikipedia.org/wiki/Debounce#Contact_bounce See the bottom of this page for a basic usage example and the "examples" folder for more. -## GITHUB PAGE - -https://github.com/thomasfredericks/Bounce2 - -## DOCUMENTATION - -The complete class documentation can be found in the "docs" folder or [online here](http://thomasfredericks.github.io/Bounce2/). - -# HAVE A QUESTION? - -Please post your questions [here](http://forum.arduino.cc/index.php?topic=266132.0). +The library is composed of three classes: +* Debouncer : The code that does the actual debouncing. Only advanced users should play with this class. +* Bounce : This is the general use library. It links the Debouncer to a hardware pin on your board. +* Button : A special version of Bounce for buttons that are pressed. # INSTALLATION & DOWNLOAD Install through your software's Library Manager or download the latest version [here](https://github.com/thomasfredericks/Bounce2/archive/master.zip) and put the "Bounce2" folder in your "libraries" folder. -The original version of Bounce (Bounce 1) is included in the download but not supported anymore. +Please note that the original version of this library (Bounce 1) is included in the "extras" folder of the download but not supported anymore. + +## BASIC USE + +### INSTANTIATE + +```cpp +#include +Bounce b = Bounce(); // Instantiate a Bounce object +``` + +### SETUP + +```cpp +b.attach ( , ); +b.interval( ); +``` +### LOOP + +```cpp +b.update(); +if ( b.changed() ) { + // THE STATE OF THE INPUT CHANGED + int deboucedValue = b.read(); + // DO SOMETHING WITH THE VALUE +} +``` -# DEBOUNCE ALGORITHMS (FOR ADVANCED USERS) +## BOUNCE EXAMPLE + +```cpp +// This example toggles the debug LED (pin 13) on or off when a button on pin 2 is pressed. + +// Include the Bounce2 library found here : +// https://github.com/thomasfredericks/Bounce2 +#include + +#define BUTTON_PIN 2 +#define LED_PIN 13 + +int ledState = LOW; + + +Bounce b = Bounce(); // Instantiate a Bounce object + +void setup() { + + b.attach(BUTTON_PIN,INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode + b.interval(25); // Use a debounce interval of 25 milliseconds + + + pinMode(LED_PIN,OUTPUT); // Setup the LED + digitalWrite(LED_PIN,ledState); // Turn off the LED + +} + +void loop() { + + b.update(); // Update the Bounce instance + + if ( b.fell() ) { // Call code if button transitions from HIGH to LOW + ledState = !ledState; // Toggle LED state + digitalWrite(LED_PIN,ledState); // Apply new LED state + } +} +``` + +## BUTTON EXAMPLE + +```cpp +/* + DESCRIPTION + ==================== + Pressing a physical button switches a LED on or off. + Simple example of the Button class from the Bounce library. + The Button class matches an electrical state to a physical action + with