Files
thomasfredericks_Bounce2/docs/files/index.html
T

114 lines
16 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://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.13"/>
<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.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
</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="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 contributions from: Eric Lowry, Jim Schimpf, Tom Harkaway, Joachim Krüger and MrGradgrind.</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: <a href="http://en.wikipedia.org/wiki/Debounce#Contact_bounce">http://en.wikipedia.org/wiki/Debounce#Contact_bounce</a></p>
<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. ">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><a class="el" href="class_button.html" title="The Debouncer:Bounce:Button class. The Button class matches an electrical state to a physical action...">Button</a> : A special version of <a class="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 &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. ">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#a47c83f13a03920d21fbfafd8469ec06b">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#a2cae68910c19c778507f257842fc41bf">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#a1ef5a04b4ebe97352ff3bb227476035c">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"> Pressing a physical button switches a LED on or off.</span></div><div class="line"><span class="comment"> Simple example of the Button class from the Bounce library.</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"> with &lt;Button&gt;.setPressedState(LOW or HIGH).</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_button.html">Button</a> button = <a class="code" href="class_button.html">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_button.html#aa58da793c244339b781349cf9af544d5">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_button.html#a8e37fb754907685539ea71183204b033">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. ">Bounce</a> library uses a stable interval to process the debouncing. This is simpler to understand and can cancel unwanted noise.</p>
<div class="image">
<img src="https://raw.github.com/thomasfredericks/Bounce-Arduino-Wiring/master/extras/BouncySwitch_stable.png"/>
</div>
<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 --><div class="image">
<img src="https://raw.github.com/thomasfredericks/Bounce-Arduino-Wiring/master/extras/BouncySwitch_lockout.png"/>
</div>
<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. <a class="el" href="class_button.html" title="The Debouncer:Bounce:Button class. The Button class matches an electrical state to a physical action...">Button</a> 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><!-- contents -->
<!-- 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.13
</small></address>
</body>
</html>