# BOUNCE 2 Debouncing library for Arduino and Wiring by Thomas Ouellet Fredericks with many contributions from the community : https://github.com/thomasfredericks/Bounce2/graphs/contributors 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: * John Errington's Experiments with an Arduino : [Using digital inputs: Switch bounce and solutions to it](http://www.skillbank.co.uk/arduino/switchbounce.htm) * Wikipedia article : 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. 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. 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 } ``` ## 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