<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.">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.">Bounce</a> for buttons that are pressed.</li>
</ul>
<h1>INSTALLATION & DOWNLOAD</h1>
<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.">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"> b.<aclass="code"href="class_debouncer.html#a72f3e8d483555031d2ac21b0b7702c06">update</a>(); <spanclass="comment">// Update the Bounce instance</span></div>
<divclass="line"></div>
<divclass="line"><spanclass="keywordflow">if</span> ( b.<aclass="code"href="class_debouncer.html#a1ef5a04b4ebe97352ff3bb227476035c">fell</a>() ) { <spanclass="comment">// Call code if button transitions from HIGH to LOW</span></div>
<divclass="line"> ledState = !ledState; <spanclass="comment">// Toggle LED state</span></div>
<divclass="line"> digitalWrite(LED_PIN,ledState); <spanclass="comment">// Apply new LED state</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.">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_a1ef5a04b4ebe97352ff3bb227476035c"><divclass="ttname"><ahref="class_debouncer.html#a1ef5a04b4ebe97352ff3bb227476035c">Debouncer::fell</a></div><divclass="ttdeci">bool fell()</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_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_debouncer_html_a2cae68910c19c778507f257842fc41bf"><divclass="ttname"><ahref="class_debouncer.html#a2cae68910c19c778507f257842fc41bf">Debouncer::read</a></div><divclass="ttdeci">bool read()</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_a47c83f13a03920d21fbfafd8469ec06b"><divclass="ttname"><ahref="class_debouncer.html#a47c83f13a03920d21fbfafd8469ec06b">Debouncer::changed</a></div><divclass="ttdeci">bool changed()</div><divclass="ttdoc">Returns true if the state changed on last update.</div><divclass="ttdef"><b>Definition:</b> Bounce2.h:129</div></div>
<divclass="ttc"id="aclass_debouncer_html_a72f3e8d483555031d2ac21b0b7702c06"><divclass="ttname"><ahref="class_debouncer.html#a72f3e8d483555031d2ac21b0b7702c06">Debouncer::update</a></div><divclass="ttdeci">bool update()</div><divclass="ttdoc">Updates the pin's state.</div><divclass="ttdef"><b>Definition:</b> Bounce2.cpp:32</div></div>
<divclass="ttc"id="aclass_bounce2_1_1_button_html_a3fbacfb9a631e03afcfaa5dc39686bad"><divclass="ttname"><ahref="class_bounce2_1_1_button.html#a3fbacfb9a631e03afcfaa5dc39686bad">Bounce2::Button::pressed</a></div><divclass="ttdeci">bool pressed()</div><divclass="ttdoc">Returns true if the button was physically pressed</div><divclass="ttdef"><b>Definition:</b> Bounce2.h:290</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.</div><divclass="ttdef"><b>Definition:</b> Bounce2.h:166</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:269</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>