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/bounce_multiple_8ino-exampl...

74 lines
5.2 KiB

<!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_multiple.ino</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_multiple.ino</div> </div>
</div><!--header-->
<div class="contents">
<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>
<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 -->
<!-- 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>