bounce_basic_8ino-example.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.17"/>
  7. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  8. <title>Bounce2: bounce_basic.ino</title>
  9. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  10. <script type="text/javascript" src="jquery.js"></script>
  11. <script type="text/javascript" src="dynsections.js"></script>
  12. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  13. <script type="text/javascript" src="search/searchdata.js"></script>
  14. <script type="text/javascript" src="search/search.js"></script>
  15. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  16. </head>
  17. <body>
  18. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  19. <div id="titlearea">
  20. <table cellspacing="0" cellpadding="0">
  21. <tbody>
  22. <tr style="height: 56px;">
  23. <td id="projectalign" style="padding-left: 0.5em;">
  24. <div id="projectname">Bounce2
  25. </div>
  26. </td>
  27. </tr>
  28. </tbody>
  29. </table>
  30. </div>
  31. <!-- end header part -->
  32. <!-- Generated by Doxygen 1.8.17 -->
  33. <script type="text/javascript">
  34. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  35. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  36. /* @license-end */
  37. </script>
  38. <script type="text/javascript" src="menudata.js"></script>
  39. <script type="text/javascript" src="menu.js"></script>
  40. <script type="text/javascript">
  41. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  42. $(function() {
  43. initMenu('',true,false,'search.php','Search');
  44. $(document).ready(function() { init_search(); });
  45. });
  46. /* @license-end */</script>
  47. <div id="main-nav"></div>
  48. </div><!-- top -->
  49. <!-- window showing the filter options -->
  50. <div id="MSearchSelectWindow"
  51. onmouseover="return searchBox.OnSearchSelectShow()"
  52. onmouseout="return searchBox.OnSearchSelectHide()"
  53. onkeydown="return searchBox.OnSearchSelectKey(event)">
  54. </div>
  55. <!-- iframe showing the search results (closed by default) -->
  56. <div id="MSearchResultsWindow">
  57. <iframe src="javascript:void(0)" frameborder="0"
  58. name="MSearchResults" id="MSearchResults">
  59. </iframe>
  60. </div>
  61. <div class="header">
  62. <div class="headertitle">
  63. <div class="title">bounce_basic.ino</div> </div>
  64. </div><!--header-->
  65. <div class="contents">
  66. <p>Basic example of 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> class.</p>
  67. <div class="fragment"><div class="line"> </div>
  68. <div class="line">/*</div>
  69. <div class="line"> DESCRIPTION</div>
  70. <div class="line"> ====================</div>
  71. <div class="line"> Simple example of the Bounce library that switches a LED when</div>
  72. <div class="line"> a state change (from HIGH to LOW) is triggered (for example when a button is pressed).</div>
  73. <div class="line"> </div>
  74. <div class="line"> Set BOUNCE_PIN to the pin attached to the input (a button for example).</div>
  75. <div class="line"> Set LED_PIN to the pin attached to a LED.</div>
  76. <div class="line"> </div>
  77. <div class="line">*/</div>
  78. <div class="line"> </div>
  79. <div class="line">// WE WILL attach() THE Bounce INSTANCE TO THE FOLLOWING PIN IN setup()</div>
  80. <div class="line">#define BOUNCE_PIN 2</div>
  81. <div class="line"> </div>
  82. <div class="line">// DEFINE THE PIN FOR THE LED :</div>
  83. <div class="line">// 1) SOME BOARDS HAVE A DEFAULT LED (LED_BUILTIN)</div>
  84. <div class="line">#define LED_PIN LED_BUILTIN</div>
  85. <div class="line">// 2) OTHERWISE SET YOUR OWN PIN</div>
  86. <div class="line">// #define LED_PIN 13</div>
  87. <div class="line"> </div>
  88. <div class="line">// Include the Bounce2 library found here :</div>
  89. <div class="line">// https://github.com/thomasfredericks/Bounce2</div>
  90. <div class="line">#include &lt;Bounce2.h&gt;</div>
  91. <div class="line"> </div>
  92. <div class="line"> </div>
  93. <div class="line">// INSTANTIATE A Bounce OBJECT</div>
  94. <div class="line">Bounce bounce = Bounce();</div>
  95. <div class="line"> </div>
  96. <div class="line">// SET A VARIABLE TO STORE THE LED STATE</div>
  97. <div class="line">int ledState = LOW;</div>
  98. <div class="line"> </div>
  99. <div class="line">void setup() {</div>
  100. <div class="line"> </div>
  101. <div class="line"> // BOUNCE SETUP</div>
  102. <div class="line"> </div>
  103. <div class="line"> // SELECT ONE OF THE FOLLOWING :</div>
  104. <div class="line"> // 1) IF YOUR INPUT HAS AN INTERNAL PULL-UP</div>
  105. <div class="line"> bounce.attach( BOUNCE_PIN , INPUT_PULLUP ); // USE INTERNAL PULL-UP</div>
  106. <div class="line"> // 2) IF YOUR INPUT USES AN EXTERNAL PULL-UP</div>
  107. <div class="line"> //bounce.attach( BOUNCE_PIN, INPUT ); // USE EXTERNAL PULL-UP</div>
  108. <div class="line"> </div>
  109. <div class="line"> // DEBOUNCE INTERVAL IN MILLISECONDS</div>
  110. <div class="line"> bounce.interval(5); // interval in ms</div>
  111. <div class="line"> </div>
  112. <div class="line"> // LED SETUP</div>
  113. <div class="line"> pinMode(LED_PIN, OUTPUT);</div>
  114. <div class="line"> digitalWrite(LED_PIN, ledState);</div>
  115. <div class="line"> </div>
  116. <div class="line">}</div>
  117. <div class="line"> </div>
  118. <div class="line">void loop() {</div>
  119. <div class="line"> // Update the Bounce instance (YOU MUST DO THIS EVERY LOOP)</div>
  120. <div class="line"> bounce.update();</div>
  121. <div class="line"> </div>
  122. <div class="line"> // &lt;Bounce&gt;.changed() RETURNS true IF THE STATE CHANGED (FROM HIGH TO LOW OR LOW TO HIGH)</div>
  123. <div class="line"> if ( bounce.changed() ) {</div>
  124. <div class="line"> // THE STATE OF THE INPUT CHANGED</div>
  125. <div class="line"> // GET THE STATE</div>
  126. <div class="line"> int deboucedInput = bounce.read();</div>
  127. <div class="line"> // IF THE CHANGED VALUE IS LOW</div>
  128. <div class="line"> if ( deboucedInput == LOW ) {</div>
  129. <div class="line"> ledState = !ledState; // SET ledState TO THE OPPOSITE OF ledState</div>
  130. <div class="line"> digitalWrite(LED_PIN,ledState); // WRITE THE NEW ledState</div>
  131. <div class="line"> }</div>
  132. <div class="line"> }</div>
  133. <div class="line"> </div>
  134. <div class="line"> </div>
  135. <div class="line"> </div>
  136. <div class="line">}</div>
  137. </div><!-- fragment --> </div><!-- contents -->
  138. <!-- start footer part -->
  139. <hr class="footer"/><address class="footer"><small>
  140. Generated by &#160;<a href="http://www.doxygen.org/index.html">
  141. <img class="footer" src="doxygen.png" alt="doxygen"/>
  142. </a> 1.8.17
  143. </small></address>
  144. </body>
  145. </html>