You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
MicroDexed/third-party/Bounce2/docs/files/index.html

242 lines
20 KiB

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Bounce2: BOUNCE 2</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">Bounce2
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="PageDoc"><div class="header">
<div class="headertitle">
<div class="title">BOUNCE 2 </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Debouncing library for Arduino and Wiring by Thomas Ouellet Fredericks with many contributions from the community : <a href="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 : <a href="http://www.skillbank.co.uk/arduino/switchbounce.htm">Using digital inputs: Switch bounce and solutions to it</a></li>
<li>Wikipedia article : <a href="http://en.wikipedia.org/wiki/Debounce#Contact_bounce">http://en.wikipedia.org/wiki/Debounce#Contact_bounce</a></li>
</ul>
<p>See the bottom of this page for a basic usage example and the "examples" folder for more.</p>
<p>The library is composed of three classes:</p><ul>
<li><a class="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><a class="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 <a class="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 <a class="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>
</ul>
<h1>INSTALLATION &amp; DOWNLOAD</h1>
<p>Install through your software's Library Manager or download the latest version <a href="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 (<a class="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>
<h2>BASIC USE</h2>
<h3>INSTANTIATE</h3>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;Bounce2.h&gt;</span></div>
<div class="line"><a class="code" href="class_bounce.html">Bounce</a> b = <a class="code" href="class_bounce.html">Bounce</a>(); <span class="comment">// Instantiate a Bounce object</span></div>
</div><!-- fragment --><h3>SETUP</h3>
<div class="fragment"><div class="line">b.<a class="code" href="class_bounce.html#aba08e592941465d033e3eba3dde66eaf">attach</a> ( &lt;PIN&gt; , &lt;PIN MODE&gt; );</div>
<div class="line">b.<a class="code" href="class_debouncer.html#a930bf3945e698d77b889f6309079857d">interval</a>( &lt;INTERVAL IN MS&gt; );</div>
</div><!-- fragment --><h3>LOOP</h3>
<div class="fragment"><div class="line">b.<a class="code" href="class_debouncer.html#a72f3e8d483555031d2ac21b0b7702c06">update</a>();</div>
<div class="line"><span class="keywordflow">if</span> ( b.<a class="code" href="class_debouncer.html#a1bbd627f9d8809b5ee9e64e9fb21e248">changed</a>() ) { </div>
<div class="line"> <span class="comment">// THE STATE OF THE INPUT CHANGED</span></div>
<div class="line"> <span class="keywordtype">int</span> deboucedValue = b.<a class="code" href="class_debouncer.html#aa5fcde9156f700c362fd49af5dd92ecd">read</a>();</div>
<div class="line"> <span class="comment">// DO SOMETHING WITH THE VALUE</span></div>
<div class="line">}</div>
</div><!-- fragment --><h2>BOUNCE EXAMPLE</h2>
<div class="fragment"><div class="line"><span class="comment">// This example toggles the debug LED (pin 13) on or off when a button on pin 2 is pressed.</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">// Include the Bounce2 library found here :</span></div>
<div class="line"><span class="comment">// https://github.com/thomasfredericks/Bounce2</span></div>
<div class="line"><span class="preprocessor">#include &lt;Bounce2.h&gt;</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#define BUTTON_PIN 2</span></div>
<div class="line"><span class="preprocessor">#define LED_PIN 13</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> ledState = LOW;</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><a class="code" href="class_bounce.html">Bounce</a> b = <a class="code" href="class_bounce.html">Bounce</a>(); <span class="comment">// Instantiate a Bounce object</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> setup() {</div>
<div class="line"> </div>
<div class="line"> b.<a class="code" href="class_bounce.html#aba08e592941465d033e3eba3dde66eaf">attach</a>(BUTTON_PIN,INPUT_PULLUP); <span class="comment">// Attach the debouncer to a pin with INPUT_PULLUP mode</span></div>
<div class="line"> b.<a class="code" href="class_debouncer.html#a930bf3945e698d77b889f6309079857d">interval</a>(25); <span class="comment">// Use a debounce interval of 25 milliseconds</span></div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> pinMode(LED_PIN,OUTPUT); <span class="comment">// Setup the LED</span></div>
<div class="line"> digitalWrite(LED_PIN,ledState); <span class="comment">// Turn off the LED</span></div>
<div class="line"> </div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> loop() {</div>
<div class="line"> </div>
<div class="line"> b.<a class="code" href="class_debouncer.html#a72f3e8d483555031d2ac21b0b7702c06">update</a>(); <span class="comment">// Update the Bounce instance</span></div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">if</span> ( b.<a class="code" href="class_debouncer.html#a80315de311b855f9787b4b6d5b7899e0">fell</a>() ) { <span class="comment">// Call code if button transitions from HIGH to LOW</span></div>
<div class="line"> ledState = !ledState; <span class="comment">// Toggle LED state</span></div>
<div class="line"> digitalWrite(LED_PIN,ledState); <span class="comment">// Apply new LED state</span></div>
<div class="line"> }</div>
<div class="line">}</div>
</div><!-- fragment --><h2>BUTTON EXAMPLE</h2>
<div class="fragment"><div class="line"><span class="comment">/* </span></div>
<div class="line"><span class="comment"> DESCRIPTION</span></div>
<div class="line"><span class="comment"> ====================</span></div>
<div class="line"><span class="comment"> This is an example of the Bounce2::Button class. </span></div>
<div class="line"><span class="comment"> When the user presses a physical button, it toggles a LED on or off.</span></div>
<div class="line"><span class="comment"> The Button class matches an electrical state to a physical action. </span></div>
<div class="line"><span class="comment"> Use .setPressedState(LOW or HIGH) to set the detection state for when the button is pressed.</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment"> INSTRUCTIONS</span></div>
<div class="line"><span class="comment"> ====================</span></div>
<div class="line"><span class="comment"> Set BUTTON_PIN to the pin attached to the button.</span></div>
<div class="line"><span class="comment"> Set LED_PIN to the pin attached to a LED.</span></div>
<div class="line"><span class="comment"> </span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">// Include the Bounce2 library found here :</span></div>
<div class="line"><span class="comment">// https://github.com/thomasfredericks/Bounce2</span></div>
<div class="line"><span class="preprocessor">#include &lt;Bounce2.h&gt;</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">// INSTANTIATE A Button OBJECT</span></div>
<div class="line"><a class="code" href="class_bounce2_1_1_button.html">Bounce2::Button</a> button = <a class="code" href="class_bounce2_1_1_button.html">Bounce2::Button</a>();</div>
<div class="line"> </div>
<div class="line"><span class="comment">// WE WILL attach() THE BUTTON TO THE FOLLOWING PIN IN setup()</span></div>
<div class="line"><span class="preprocessor">#define BUTTON_PIN 39 </span></div>
<div class="line"> </div>
<div class="line"><span class="comment">// DEFINE THE PIN FOR THE LED :</span></div>
<div class="line"><span class="comment">// 1) SOME BOARDS HAVE A DEFAULT LED (LED_BUILTIN)</span></div>
<div class="line"><span class="comment">//#define LED_PIN LED_BUILTIN</span></div>
<div class="line"><span class="comment">// 2) OTHERWISE SET YOUR OWN PIN</span></div>
<div class="line"><span class="preprocessor">#define LED_PIN 13</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">// SET A VARIABLE TO STORE THE LED STATE</span></div>
<div class="line"><span class="keywordtype">bool</span> ledState = LOW;</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> setup() {</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// BUTTON SETUP </span></div>
<div class="line"> </div>
<div class="line"> <span class="comment">// SELECT ONE OF THE FOLLOWING :</span></div>
<div class="line"> <span class="comment">// 1) IF YOUR BUTTON HAS AN INTERNAL PULL-UP</span></div>
<div class="line"> <span class="comment">// button.attach( BUTTON_PIN , INPUT_PULLUP ); // USE INTERNAL PULL-UP</span></div>
<div class="line"> <span class="comment">// 2) IF YOUR BUTTON USES AN EXTERNAL PULL-UP</span></div>
<div class="line"> button.<a class="code" href="class_bounce.html#aba08e592941465d033e3eba3dde66eaf">attach</a>( BUTTON_PIN, INPUT ); <span class="comment">// USE EXTERNAL PULL-UP</span></div>
<div class="line"> </div>
<div class="line"> <span class="comment">// DEBOUNCE INTERVAL IN MILLISECONDS</span></div>
<div class="line"> button.<a class="code" href="class_debouncer.html#a930bf3945e698d77b889f6309079857d">interval</a>(5); </div>
<div class="line"> </div>
<div class="line"> <span class="comment">// INDICATE THAT THE LOW STATE CORRESPONDS TO PHYSICALLY PRESSING THE BUTTON</span></div>
<div class="line"> button.<a class="code" href="class_bounce2_1_1_button.html#a3c88b7938b26bca9dc2c7e72aedc442e">setPressedState</a>(LOW); </div>
<div class="line"> </div>
<div class="line"> <span class="comment">// LED SETUP</span></div>
<div class="line"> pinMode(LED_PIN,OUTPUT);</div>
<div class="line"> digitalWrite(LED_PIN,ledState);</div>
<div class="line"> </div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> loop() {</div>
<div class="line"> <span class="comment">// UPDATE THE BUTTON</span></div>
<div class="line"> <span class="comment">// YOU MUST CALL THIS EVERY LOOP</span></div>
<div class="line"> button.<a class="code" href="class_debouncer.html#a72f3e8d483555031d2ac21b0b7702c06">update</a>();</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">if</span> ( button.<a class="code" href="class_bounce2_1_1_button.html#a61541ae21354cb7f5cc5bc8c05db59dd">pressed</a>() ) {</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// TOGGLE THE LED STATE : </span></div>
<div class="line"> ledState = !ledState; <span class="comment">// SET ledState TO THE OPPOSITE OF ledState</span></div>
<div class="line"> digitalWrite(LED_PIN,ledState);</div>
<div class="line"> </div>
<div class="line"> }</div>
<div class="line">}</div>
</div><!-- fragment --><h1>DOCUMENTATION</h1>
<p>The complete class documentation can be found in the "docs" folder or <a href="http://thomasfredericks.github.io/Bounce2/">online here</a>.</p>
<h2>GITHUB PAGE (SOURCE CODE)</h2>
<p><a href="https://github.com/thomasfredericks/Bounce2">https://github.com/thomasfredericks/Bounce2</a></p>
<h1>HAVE A QUESTION?</h1>
<p>Please post your questions <a href="http://forum.arduino.cc/index.php?topic=266132.0">here</a>.</p>
<h1>ALTERNATE DEBOUNCE ALGORITHMS FOR ADVANCED USERS AND SPECIFIC CASES</h1>
<h2>STABLE INTERVAL</h2>
<p>By default, the <a class="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><img src="https://raw.github.com/thomasfredericks/Bounce-Arduino-Wiring/master/extras/BouncySwitch_stable.png" alt="" class="inline"/></p>
<h2>LOCK-OUT INTERVAL</h2>
<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 class="fragment"><div class="line">#define BOUNCE_LOCK_OUT</div>
</div><!-- fragment --><p><img src="https://raw.github.com/thomasfredericks/Bounce-Arduino-Wiring/master/extras/BouncySwitch_lockout.png" alt="" class="inline"/></p>
<h2>WITH PROMPT DETECTION</h2>
<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>
</ul>
<div class="fragment"><div class="line">#define BOUNCE_WITH_PROMPT_DETECTION</div>
</div><!-- fragment --> </div></div><!-- PageDoc -->
</div><!-- contents -->
<div class="ttc" id="aclass_bounce2_1_1_button_html"><div class="ttname"><a href="class_bounce2_1_1_button.html">Bounce2::Button</a></div><div class="ttdef"><b>Definition:</b> Bounce2.h:276</div></div>
<div class="ttc" id="aclass_debouncer_html_a930bf3945e698d77b889f6309079857d"><div class="ttname"><a href="class_debouncer.html#a930bf3945e698d77b889f6309079857d">Debouncer::interval</a></div><div class="ttdeci">void interval(uint16_t interval_millis)</div><div class="ttdoc">Sets the debounce interval in milliseconds.</div><div class="ttdef"><b>Definition:</b> Bounce2.cpp:14</div></div>
<div class="ttc" id="aclass_bounce2_1_1_button_html_a61541ae21354cb7f5cc5bc8c05db59dd"><div class="ttname"><a href="class_bounce2_1_1_button.html#a61541ae21354cb7f5cc5bc8c05db59dd">Bounce2::Button::pressed</a></div><div class="ttdeci">bool pressed() const</div><div class="ttdoc">Returns true if the button was physically pressed</div><div class="ttdef"><b>Definition:</b> Bounce2.h:320</div></div>
<div class="ttc" id="aclass_debouncer_html_a72f3e8d483555031d2ac21b0b7702c06"><div class="ttname"><a href="class_debouncer.html#a72f3e8d483555031d2ac21b0b7702c06">Debouncer::update</a></div><div class="ttdeci">bool update()</div><div class="ttdoc">Updates the pin's state.</div><div class="ttdef"><b>Definition:</b> Bounce2.cpp:32</div></div>
<div class="ttc" id="aclass_bounce_html"><div class="ttname"><a href="class_bounce.html">Bounce</a></div><div class="ttdoc">The Debouncer:Bounce class. Links the Deboucing class to a hardware pin. This class is odly named,...</div><div class="ttdef"><b>Definition:</b> Bounce2.h:184</div></div>
<div class="ttc" id="aclass_bounce2_1_1_button_html_a3c88b7938b26bca9dc2c7e72aedc442e"><div class="ttname"><a href="class_bounce2_1_1_button.html#a3c88b7938b26bca9dc2c7e72aedc442e">Bounce2::Button::setPressedState</a></div><div class="ttdeci">void setPressedState(bool state)</div><div class="ttdoc">Set the electrical state (HIGH/LOW) that corresponds to a physical press. By default,...</div><div class="ttdef"><b>Definition:</b> Bounce2.h:299</div></div>
<div class="ttc" id="aclass_debouncer_html_a80315de311b855f9787b4b6d5b7899e0"><div class="ttname"><a href="class_debouncer.html#a80315de311b855f9787b4b6d5b7899e0">Debouncer::fell</a></div><div class="ttdeci">bool fell() const</div><div class="ttdoc">Returns true if pin signal transitions from high to low.</div><div class="ttdef"><b>Definition:</b> Bounce2.cpp:128</div></div>
<div class="ttc" id="aclass_bounce_html_aba08e592941465d033e3eba3dde66eaf"><div class="ttname"><a href="class_bounce.html#aba08e592941465d033e3eba3dde66eaf">Bounce::attach</a></div><div class="ttdeci">void attach(int pin, int mode)</div><div class="ttdoc">Attach to a pin and sets that pin's mode (INPUT, INPUT_PULLUP or OUTPUT).</div><div class="ttdef"><b>Definition:</b> Bounce2.cpp:149</div></div>
<div class="ttc" id="aclass_debouncer_html_aa5fcde9156f700c362fd49af5dd92ecd"><div class="ttname"><a href="class_debouncer.html#aa5fcde9156f700c362fd49af5dd92ecd">Debouncer::read</a></div><div class="ttdeci">bool read() const</div><div class="ttdoc">Returns the pin's state (HIGH or LOW).</div><div class="ttdef"><b>Definition:</b> Bounce2.cpp:118</div></div>
<div class="ttc" id="aclass_debouncer_html_a1bbd627f9d8809b5ee9e64e9fb21e248"><div class="ttname"><a href="class_debouncer.html#a1bbd627f9d8809b5ee9e64e9fb21e248">Debouncer::changed</a></div><div class="ttdeci">bool changed() const</div><div class="ttdoc">Returns true if the state changed on last update.</div><div class="ttdef"><b>Definition:</b> Bounce2.h:130</div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.17
</small></address>
</body>
</html>