bounce_multiple_8ino-example.html 5.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://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.13"/>
  7. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  8. <title>Bounce2: bounce_multiple.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.13 -->
  33. <script type="text/javascript">
  34. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  35. </script>
  36. <script type="text/javascript" src="menudata.js"></script>
  37. <script type="text/javascript" src="menu.js"></script>
  38. <script type="text/javascript">
  39. $(function() {
  40. initMenu('',true,false,'search.php','Search');
  41. $(document).ready(function() { init_search(); });
  42. });
  43. </script>
  44. <div id="main-nav"></div>
  45. </div><!-- top -->
  46. <!-- window showing the filter options -->
  47. <div id="MSearchSelectWindow"
  48. onmouseover="return searchBox.OnSearchSelectShow()"
  49. onmouseout="return searchBox.OnSearchSelectHide()"
  50. onkeydown="return searchBox.OnSearchSelectKey(event)">
  51. </div>
  52. <!-- iframe showing the search results (closed by default) -->
  53. <div id="MSearchResultsWindow">
  54. <iframe src="javascript:void(0)" frameborder="0"
  55. name="MSearchResults" id="MSearchResults">
  56. </iframe>
  57. </div>
  58. <div class="header">
  59. <div class="headertitle">
  60. <div class="title">bounce_multiple.ino</div> </div>
  61. </div><!--header-->
  62. <div class="contents">
  63. <p>Detect the falling edge of multiple buttons. Eight buttons with internal pullups. Toggles a LED when any button is pressed. Buttons on pins 2,3,4,5,6,7,8,9</p>
  64. <div class="fragment"><div class="line">// Detect the falling edge of multiple buttons.</div><div class="line">// Eight buttons with internal pullups.</div><div class="line">// Toggles a LED when any button is pressed.</div><div class="line">// Buttons on pins 2,3,4,5,6,7,8,9</div><div class="line"></div><div class="line">// Include the Bounce2 library found here :</div><div class="line">// https://github.com/thomasfredericks/Bounce2</div><div class="line">#include &lt;Bounce2.h&gt;</div><div class="line"></div><div class="line">#define LED_PIN 13</div><div class="line"></div><div class="line">#define NUM_BUTTONS 8</div><div class="line">const uint8_t BUTTON_PINS[NUM_BUTTONS] = {2, 3, 4, 5, 6, 7, 8, 9};</div><div class="line"></div><div class="line">int ledState = LOW;</div><div class="line"></div><div class="line">Bounce * buttons = new Bounce[NUM_BUTTONS];</div><div class="line"></div><div class="line">void setup() {</div><div class="line"></div><div class="line"> for (int i = 0; i &lt; NUM_BUTTONS; i++) {</div><div class="line"> buttons[i].attach( BUTTON_PINS[i] , INPUT_PULLUP ); //setup the bounce instance for the current button</div><div class="line"> buttons[i].interval(25); // interval in ms</div><div class="line"> }</div><div class="line"></div><div class="line"> // Setup the LED :</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"></div><div class="line">void loop() {</div><div class="line"></div><div class="line"> bool needToToggleLed = false;</div><div class="line"></div><div class="line"></div><div class="line"> for (int i = 0; i &lt; NUM_BUTTONS; i++) {</div><div class="line"> // Update the Bounce instance :</div><div class="line"> buttons[i].update();</div><div class="line"> // If it fell, flag the need to toggle the LED</div><div class="line"> if ( buttons[i].fell() ) {</div><div class="line"> needToToggleLed = true;</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line"> // if a LED toggle has been flagged :</div><div class="line"> if ( needToToggleLed ) {</div><div class="line"> // Toggle LED state :</div><div class="line"> ledState = !ledState;</div><div class="line"> digitalWrite(LED_PIN, ledState);</div><div class="line"> }</div><div class="line"></div><div class="line"></div><div class="line">}</div><div class="line"></div></div><!-- fragment --> </div><!-- contents -->
  65. <!-- start footer part -->
  66. <hr class="footer"/><address class="footer"><small>
  67. Generated by &#160;<a href="http://www.doxygen.org/index.html">
  68. <img class="footer" src="doxygen.png" alt="doxygen"/>
  69. </a> 1.8.13
  70. </small></address>
  71. </body>
  72. </html>