<divclass="textblock"><p>Debouncing library for Arduino and Wiring by Thomas Ouellet Fredericks with many contributions from the community : <ahref="https://github.com/thomasfredericks/Bounce2/graphs/contributors">https://github.com/thomasfredericks/Bounce2/graphs/contributors</a></p>
<p>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:</p><ul>
<li>John Errington's Experiments with an Arduino : <ahref="http://www.skillbank.co.uk/arduino/switchbounce.htm">Using digital inputs: Switch bounce and solutions to it</a></li>
<p>The library is composed of three classes:</p><ul>
<li><aclass="el"href="class_debouncer.html"title="The Debouce class. Just the deboucing code separated from all harware.">Debouncer</a> : The code that does the actual debouncing. Only advanced users should play with this class.</li>
<li><aclass="el"href="class_bounce.html"title="The Debouncer:Bounce class. Links the Deboucing class to a hardware pin. This class is odly named,...">Bounce</a> : This is the general use library. It links the <aclass="el"href="class_debouncer.html"title="The Debouce class. Just the deboucing code separated from all harware.">Debouncer</a> to a hardware pin on your board.</li>
<li>Button : A special version of <aclass="el"href="class_bounce.html"title="The Debouncer:Bounce class. Links the Deboucing class to a hardware pin. This class is odly named,...">Bounce</a> for buttons that are pressed.</li>
<p>Install through your software's Library Manager or download the latest version <ahref="https://github.com/thomasfredericks/Bounce2/archive/master.zip">here</a> and put the "Bounce2" folder in your "libraries" folder.</p>
<p>Please note that the original version of this library (<aclass="el"href="class_bounce.html"title="The Debouncer:Bounce class. Links the Deboucing class to a hardware pin. This class is odly named,...">Bounce</a> 1) is included in the "extras" folder of the download but not supported anymore.</p>
<divclass="line"><aclass="code"href="class_bounce.html">Bounce</a> b = <aclass="code"href="class_bounce.html">Bounce</a>(); <spanclass="comment">// Instantiate a Bounce object</span></div>
<divclass="line"><spanclass="comment">// DO SOMETHING WITH THE VALUE</span></div>
<divclass="line">}</div>
</div><!-- fragment --><h2>BOUNCE EXAMPLE</h2>
<divclass="fragment"><divclass="line"><spanclass="comment">// This example toggles the debug LED (pin 13) on or off when a button on pin 2 is pressed.</span></div>
<divclass="line"></div>
<divclass="line"><spanclass="comment">// Include the Bounce2 library found here :</span></div>
<divclass="line"><aclass="code"href="class_bounce.html">Bounce</a> b = <aclass="code"href="class_bounce.html">Bounce</a>(); <spanclass="comment">// Instantiate a Bounce object</span></div>
<divclass="line"> b.<aclass="code"href="class_bounce.html#aba08e592941465d033e3eba3dde66eaf">attach</a>(BUTTON_PIN,INPUT_PULLUP); <spanclass="comment">// Attach the debouncer to a pin with INPUT_PULLUP mode</span></div>
<divclass="line"> b.<aclass="code"href="class_debouncer.html#a930bf3945e698d77b889f6309079857d">interval</a>(25); <spanclass="comment">// Use a debounce interval of 25 milliseconds</span></div>
<divclass="line"></div>
<divclass="line"></div>
<divclass="line"> pinMode(LED_PIN,OUTPUT); <spanclass="comment">// Setup the LED</span></div>
<divclass="line"> digitalWrite(LED_PIN,ledState); <spanclass="comment">// Turn off the LED</span></div>
<divclass="line"><spanclass="keywordflow">if</span> ( b.<aclass="code"href="class_debouncer.html#a80315de311b855f9787b4b6d5b7899e0">fell</a>() ) { <spanclass="comment">// Call code if button transitions from HIGH to LOW</span></div>
<p>By default, the <aclass="el"href="class_bounce.html"title="The Debouncer:Bounce class. Links the Deboucing class to a hardware pin. This class is odly named,...">Bounce</a> library uses a stable interval to process the debouncing. This is simpler to understand and can cancel unwanted noise.</p>
<p>By defining "#define BOUNCE_LOCK_OUT" in "Bounce.h" (or in your code before including "Bounce.h") you can activate an alternative debouncing method. This method is a lot more responsive, but does not cancel noise.</p>
</div><!-- fragment --><p><imgsrc="https://raw.github.com/thomasfredericks/Bounce-Arduino-Wiring/master/extras/BouncySwitch_lockout.png"alt=""class="inline"/></p>
<p>By defining "#define BOUNCE_WITH_PROMPT_DETECTION" in "Bounce.h" (or in your code before including "Bounce.h") you can activate an alternative debouncing method. Button state changes are available immediately so long as the previous state has been stable for the timeout period. Otherwise the state will be updated as soon as the timeout period allows.</p>
<ul>
<li>Able to report acurate switch time normally with no delay.</li>
<li>Use when accurate switch transition timing is important.</li>
<divclass="ttc"id="aclass_debouncer_html_a930bf3945e698d77b889f6309079857d"><divclass="ttname"><ahref="class_debouncer.html#a930bf3945e698d77b889f6309079857d">Debouncer::interval</a></div><divclass="ttdeci">void interval(uint16_t interval_millis)</div><divclass="ttdoc">Sets the debounce interval in milliseconds.</div><divclass="ttdef"><b>Definition:</b> Bounce2.cpp:14</div></div>
<divclass="ttc"id="aclass_bounce2_1_1_button_html_a61541ae21354cb7f5cc5bc8c05db59dd"><divclass="ttname"><ahref="class_bounce2_1_1_button.html#a61541ae21354cb7f5cc5bc8c05db59dd">Bounce2::Button::pressed</a></div><divclass="ttdeci">bool pressed() const</div><divclass="ttdoc">Returns true if the button was physically pressed</div><divclass="ttdef"><b>Definition:</b> Bounce2.h:320</div></div>
<divclass="ttc"id="aclass_bounce_html"><divclass="ttname"><ahref="class_bounce.html">Bounce</a></div><divclass="ttdoc">The Debouncer:Bounce class. Links the Deboucing class to a hardware pin. This class is odly named,...</div><divclass="ttdef"><b>Definition:</b> Bounce2.h:184</div></div>
<divclass="ttc"id="aclass_bounce2_1_1_button_html_a3c88b7938b26bca9dc2c7e72aedc442e"><divclass="ttname"><ahref="class_bounce2_1_1_button.html#a3c88b7938b26bca9dc2c7e72aedc442e">Bounce2::Button::setPressedState</a></div><divclass="ttdeci">void setPressedState(bool state)</div><divclass="ttdoc">Set the electrical state (HIGH/LOW) that corresponds to a physical press. By default,...</div><divclass="ttdef"><b>Definition:</b> Bounce2.h:299</div></div>
<divclass="ttc"id="aclass_debouncer_html_a80315de311b855f9787b4b6d5b7899e0"><divclass="ttname"><ahref="class_debouncer.html#a80315de311b855f9787b4b6d5b7899e0">Debouncer::fell</a></div><divclass="ttdeci">bool fell() const</div><divclass="ttdoc">Returns true if pin signal transitions from high to low.</div><divclass="ttdef"><b>Definition:</b> Bounce2.cpp:128</div></div>
<divclass="ttc"id="aclass_bounce_html_aba08e592941465d033e3eba3dde66eaf"><divclass="ttname"><ahref="class_bounce.html#aba08e592941465d033e3eba3dde66eaf">Bounce::attach</a></div><divclass="ttdeci">void attach(int pin, int mode)</div><divclass="ttdoc">Attach to a pin and sets that pin's mode (INPUT, INPUT_PULLUP or OUTPUT).</div><divclass="ttdef"><b>Definition:</b> Bounce2.cpp:149</div></div>
<divclass="ttc"id="aclass_debouncer_html_aa5fcde9156f700c362fd49af5dd92ecd"><divclass="ttname"><ahref="class_debouncer.html#aa5fcde9156f700c362fd49af5dd92ecd">Debouncer::read</a></div><divclass="ttdeci">bool read() const</div><divclass="ttdoc">Returns the pin's state (HIGH or LOW).</div><divclass="ttdef"><b>Definition:</b> Bounce2.cpp:118</div></div>
<divclass="ttc"id="aclass_debouncer_html_a1bbd627f9d8809b5ee9e64e9fb21e248"><divclass="ttname"><ahref="class_debouncer.html#a1bbd627f9d8809b5ee9e64e9fb21e248">Debouncer::changed</a></div><divclass="ttdeci">bool changed() const</div><divclass="ttdoc">Returns true if the state changed on last update.</div><divclass="ttdef"><b>Definition:</b> Bounce2.h:130</div></div>