1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <!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: src/Bounce2.h Source File</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>
- <!-- 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 id="nav-path" class="navpath">
- <ul>
- <li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li> </ul>
- </div>
- </div><!-- top -->
- <div class="header">
- <div class="headertitle">
- <div class="title">Bounce2.h</div> </div>
- </div><!--header-->
- <div class="contents">
- <div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="comment">/*</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="comment"> The MIT License (MIT)</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment"></span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment"> Copyright (c) 2013 thomasfredericks</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="comment"></span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="comment"> Permission is hereby granted, free of charge, to any person obtaining a copy of</span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="comment"> this software and associated documentation files (the "Software"), to deal in</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="comment"> the Software without restriction, including without limitation the rights to</span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="comment"> use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of</span></div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="comment"> the Software, and to permit persons to whom the Software is furnished to do so,</span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="comment"> subject to the following conditions:</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment"></span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span> <span class="comment"> The above copyright notice and this permission notice shall be included in all</span></div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="comment"> copies or substantial portions of the Software.</span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="comment"></span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span> <span class="comment"> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span></div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="comment"> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS</span></div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="comment"> FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR</span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span> <span class="comment"> COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER</span></div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="comment"> IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN</span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="comment"> CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> <span class="comment">*/</span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> </div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="comment">/* * * * * * * * * * * * * * * * * * * * * * * * * * * *</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> <span class="comment"> Main code by Thomas O Fredericks (tof@t-o-f.info)</span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="comment"> Previous contributions by Eric Lowry, Jim Schimpf and Tom Harkaway</span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="comment"> * * * * * * * * * * * * * * * * * * * * * * * * * * * * */</span></div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span> </div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span> <span class="preprocessor">#ifndef Bounce2_h</span></div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="preprocessor">#define Bounce2_h</span></div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span> </div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span> <span class="preprocessor">#if defined(ARDUINO) && ARDUINO >= 100</span></div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span> <span class="preprocessor">#include "Arduino.h"</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span> <span class="preprocessor">#else</span></div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span> <span class="preprocessor">#include "WProgram.h"</span></div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span> <span class="preprocessor">#endif</span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span> </div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span> <span class="comment">// Uncomment the following line for "LOCK-OUT" debounce method</span></div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span> <span class="comment">//#define BOUNCE_LOCK_OUT</span></div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span> </div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span> <span class="comment">// Uncomment the following line for "BOUNCE_WITH_PROMPT_DETECTION" debounce method</span></div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span> <span class="comment">//#define BOUNCE_WITH_PROMPT_DETECTION</span></div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span> </div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span> <span class="preprocessor">#include <inttypes.h></span></div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span> </div><div class="line"><a name="l00069"></a><span class="lineno"><a class="line" href="class_bounce.html"> 69</a></span> <span class="keyword">class </span><a class="code" href="class_bounce.html">Bounce</a></div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span> {</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>  <span class="keyword">public</span>:</div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span> </div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  <a class="code" href="class_bounce.html#aa62a2e2b5ad0ee6913a95f2f2a0e7606">Bounce</a>();</div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span> </div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span> </div><div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  <span class="keywordtype">void</span> <a class="code" href="class_bounce.html#aba08e592941465d033e3eba3dde66eaf">attach</a>(<span class="keywordtype">int</span> pin, <span class="keywordtype">int</span> mode);</div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span> </div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  <span class="keywordtype">void</span> <a class="code" href="class_bounce.html#aba08e592941465d033e3eba3dde66eaf">attach</a>(<span class="keywordtype">int</span> pin);</div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  </div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span> </div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  <span class="keywordtype">void</span> <a class="code" href="class_bounce.html#a2c6e68bf749497c597a9437b488b3d7c">interval</a>(uint16_t interval_millis);</div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span> </div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span> </div><div class="line"><a name="l00121"></a><span class="lineno"> 121</span>  <span class="keywordtype">bool</span> <a class="code" href="class_bounce.html#ab36d7b83bf32e0935a0c2c6a05096441">update</a>();</div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span> </div><div class="line"><a name="l00128"></a><span class="lineno"> 128</span>  <span class="keywordtype">bool</span> <a class="code" href="class_bounce.html#ae1936fdf44501992707e6cbaee9bbc76">read</a>();</div><div class="line"><a name="l00129"></a><span class="lineno"> 129</span> </div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span>  <span class="keywordtype">bool</span> <a class="code" href="class_bounce.html#abfbb0910f5b1ec4e25315cff26dd6289">fell</a>();</div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span> </div><div class="line"><a name="l00138"></a><span class="lineno"> 138</span>  <span class="keywordtype">bool</span> <a class="code" href="class_bounce.html#a9e4187934576e568cdfa8f94efeff6f2">rose</a>();</div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span> </div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span>  </div><div class="line"><a name="l00144"></a><span class="lineno"><a class="line" href="class_bounce.html#a3417beb80eb6593d768c2e9884c57aa0"> 144</a></span>  <span class="keywordtype">bool</span> <a class="code" href="class_bounce.html#a3417beb80eb6593d768c2e9884c57aa0">risingEdge</a>() { <span class="keywordflow">return</span> <a class="code" href="class_bounce.html#a9e4187934576e568cdfa8f94efeff6f2">rose</a>(); }</div><div class="line"><a name="l00148"></a><span class="lineno"><a class="line" href="class_bounce.html#ac756559419bfa1c5060e5e4a4ad6406f"> 148</a></span>  <span class="keywordtype">bool</span> <a class="code" href="class_bounce.html#ac756559419bfa1c5060e5e4a4ad6406f">fallingEdge</a>() { <span class="keywordflow">return</span> <a class="code" href="class_bounce.html#abfbb0910f5b1ec4e25315cff26dd6289">fell</a>(); }</div><div class="line"><a name="l00152"></a><span class="lineno"><a class="line" href="class_bounce.html#ab34517094faf21d4f38b36da2915132b"> 152</a></span>  <a class="code" href="class_bounce.html#ab34517094faf21d4f38b36da2915132b">Bounce</a>(uint8_t pin, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> interval_millis ) : <a class="code" href="class_bounce.html">Bounce</a>() {</div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span>  <a class="code" href="class_bounce.html#aba08e592941465d033e3eba3dde66eaf">attach</a>(pin);</div><div class="line"><a name="l00154"></a><span class="lineno"> 154</span>  <a class="code" href="class_bounce.html#a2c6e68bf749497c597a9437b488b3d7c">interval</a>(interval_millis);</div><div class="line"><a name="l00155"></a><span class="lineno"> 155</span>  }</div><div class="line"><a name="l00156"></a><span class="lineno"> 156</span>  </div><div class="line"><a name="l00165"></a><span class="lineno"> 165</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <a class="code" href="class_bounce.html#a62412d814d36102ab3d285e801d5d29a">duration</a>();</div><div class="line"><a name="l00166"></a><span class="lineno"> 166</span> </div><div class="line"><a name="l00167"></a><span class="lineno"> 167</span> </div><div class="line"><a name="l00168"></a><span class="lineno"> 168</span>  <span class="comment">// WIP HELD : unsigned long held(); // Returns the duration the previous state was held</span></div><div class="line"><a name="l00169"></a><span class="lineno"> 169</span> </div><div class="line"><a name="l00170"></a><span class="lineno"> 170</span>  <span class="keyword">protected</span>:</div><div class="line"><a name="l00171"></a><span class="lineno"> 171</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> previous_millis;</div><div class="line"><a name="l00172"></a><span class="lineno"> 172</span>  uint16_t interval_millis;</div><div class="line"><a name="l00173"></a><span class="lineno"> 173</span>  uint8_t state;</div><div class="line"><a name="l00174"></a><span class="lineno"> 174</span>  uint8_t pin;</div><div class="line"><a name="l00175"></a><span class="lineno"> 175</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> stateChangeLastTime;</div><div class="line"><a name="l00176"></a><span class="lineno"> 176</span>  <span class="comment">// WIP HELD : unsigned long durationOfPreviousState;</span></div><div class="line"><a name="l00177"></a><span class="lineno"> 177</span>  <span class="keyword">virtual</span> <span class="keywordtype">bool</span> readCurrentState() { <span class="keywordflow">return</span> digitalRead(pin); }</div><div class="line"><a name="l00178"></a><span class="lineno"> 178</span>  <span class="keyword">virtual</span> <span class="keywordtype">void</span> setPinMode(<span class="keywordtype">int</span> pin, <span class="keywordtype">int</span> mode) {</div><div class="line"><a name="l00179"></a><span class="lineno"> 179</span> <span class="preprocessor">#if defined(ARDUINO_STM_NUCLEO_F103RB) || defined(ARDUINO_GENERIC_STM32F103C)</span></div><div class="line"><a name="l00180"></a><span class="lineno"> 180</span>  pinMode(pin, (WiringPinMode)mode);</div><div class="line"><a name="l00181"></a><span class="lineno"> 181</span> <span class="preprocessor">#else</span></div><div class="line"><a name="l00182"></a><span class="lineno"> 182</span>  pinMode(pin, mode);</div><div class="line"><a name="l00183"></a><span class="lineno"> 183</span> <span class="preprocessor">#endif</span></div><div class="line"><a name="l00184"></a><span class="lineno"> 184</span>  }</div><div class="line"><a name="l00185"></a><span class="lineno"> 185</span> </div><div class="line"><a name="l00186"></a><span class="lineno"> 186</span>  <span class="keyword">private</span>:</div><div class="line"><a name="l00187"></a><span class="lineno"> 187</span>  <span class="keyword">inline</span> <span class="keywordtype">void</span> changeState();</div><div class="line"><a name="l00188"></a><span class="lineno"> 188</span>  <span class="keyword">inline</span> <span class="keywordtype">void</span> setStateFlag(<span class="keyword">const</span> uint8_t flag) {state |= flag;}</div><div class="line"><a name="l00189"></a><span class="lineno"> 189</span>  <span class="keyword">inline</span> <span class="keywordtype">void</span> unsetStateFlag(<span class="keyword">const</span> uint8_t flag) {state &= ~flag;}</div><div class="line"><a name="l00190"></a><span class="lineno"> 190</span>  <span class="keyword">inline</span> <span class="keywordtype">void</span> toggleStateFlag(<span class="keyword">const</span> uint8_t flag) {state ^= flag;}</div><div class="line"><a name="l00191"></a><span class="lineno"> 191</span>  <span class="keyword">inline</span> <span class="keywordtype">bool</span> getStateFlag(<span class="keyword">const</span> uint8_t flag) {<span class="keywordflow">return</span>((state & flag) != 0);}</div><div class="line"><a name="l00192"></a><span class="lineno"> 192</span> };</div><div class="line"><a name="l00193"></a><span class="lineno"> 193</span> </div><div class="line"><a name="l00194"></a><span class="lineno"> 194</span> <span class="preprocessor">#endif</span></div><div class="ttc" id="class_bounce_html"><div class="ttname"><a href="class_bounce.html">Bounce</a></div><div class="ttdef"><b>Definition:</b> Bounce2.h:69</div></div>
- <div class="ttc" id="class_bounce_html_ae1936fdf44501992707e6cbaee9bbc76"><div class="ttname"><a href="class_bounce.html#ae1936fdf44501992707e6cbaee9bbc76">Bounce::read</a></div><div class="ttdeci">bool read()</div><div class="ttdoc">Returns the pin&#39;s state (HIGH or LOW). </div><div class="ttdef"><b>Definition:</b> Bounce2.cpp:127</div></div>
- <div class="ttc" id="class_bounce_html_a2c6e68bf749497c597a9437b488b3d7c"><div class="ttname"><a href="class_bounce.html#a2c6e68bf749497c597a9437b488b3d7c">Bounce::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:36</div></div>
- <div class="ttc" id="class_bounce_html_ac756559419bfa1c5060e5e4a4ad6406f"><div class="ttname"><a href="class_bounce.html#ac756559419bfa1c5060e5e4a4ad6406f">Bounce::fallingEdge</a></div><div class="ttdeci">bool fallingEdge()</div><div class="ttdoc">Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...</div><div class="ttdef"><b>Definition:</b> Bounce2.h:148</div></div>
- <div class="ttc" id="class_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&#39;s mode (INPUT, INPUT_PULLUP or OUTPUT). </div><div class="ttdef"><b>Definition:</b> Bounce2.cpp:31</div></div>
- <div class="ttc" id="class_bounce_html_abfbb0910f5b1ec4e25315cff26dd6289"><div class="ttname"><a href="class_bounce.html#abfbb0910f5b1ec4e25315cff26dd6289">Bounce::fell</a></div><div class="ttdeci">bool fell()</div><div class="ttdoc">Returns true if pin signal transitions from high to low. </div><div class="ttdef"><b>Definition:</b> Bounce2.cpp:137</div></div>
- <div class="ttc" id="class_bounce_html_ab36d7b83bf32e0935a0c2c6a05096441"><div class="ttname"><a href="class_bounce.html#ab36d7b83bf32e0935a0c2c6a05096441">Bounce::update</a></div><div class="ttdeci">bool update()</div><div class="ttdoc">Updates the pin&#39;s state. </div><div class="ttdef"><b>Definition:</b> Bounce2.cpp:41</div></div>
- <div class="ttc" id="class_bounce_html_a3417beb80eb6593d768c2e9884c57aa0"><div class="ttname"><a href="class_bounce.html#a3417beb80eb6593d768c2e9884c57aa0">Bounce::risingEdge</a></div><div class="ttdeci">bool risingEdge()</div><div class="ttdoc">Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...</div><div class="ttdef"><b>Definition:</b> Bounce2.h:144</div></div>
- <div class="ttc" id="class_bounce_html_a62412d814d36102ab3d285e801d5d29a"><div class="ttname"><a href="class_bounce.html#a62412d814d36102ab3d285e801d5d29a">Bounce::duration</a></div><div class="ttdeci">unsigned long duration()</div><div class="ttdoc">Returns the duration in milliseconds of the current state. </div><div class="ttdef"><b>Definition:</b> Bounce2.cpp:116</div></div>
- <div class="ttc" id="class_bounce_html_ab34517094faf21d4f38b36da2915132b"><div class="ttname"><a href="class_bounce.html#ab34517094faf21d4f38b36da2915132b">Bounce::Bounce</a></div><div class="ttdeci">Bounce(uint8_t pin, unsigned long interval_millis)</div><div class="ttdoc">Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...</div><div class="ttdef"><b>Definition:</b> Bounce2.h:152</div></div>
- <div class="ttc" id="class_bounce_html_aa62a2e2b5ad0ee6913a95f2f2a0e7606"><div class="ttname"><a href="class_bounce.html#aa62a2e2b5ad0ee6913a95f2f2a0e7606">Bounce::Bounce</a></div><div class="ttdeci">Bounce()</div><div class="ttdoc">Create an instance of the Bounce class. </div><div class="ttdef"><b>Definition:</b> Bounce2.cpp:11</div></div>
- <div class="ttc" id="class_bounce_html_a9e4187934576e568cdfa8f94efeff6f2"><div class="ttname"><a href="class_bounce.html#a9e4187934576e568cdfa8f94efeff6f2">Bounce::rose</a></div><div class="ttdeci">bool rose()</div><div class="ttdoc">Returns true if pin signal transitions from low to high. </div><div class="ttdef"><b>Definition:</b> Bounce2.cpp:132</div></div>
- </div><!-- fragment --></div><!-- contents -->
- <!-- start footer part -->
- <hr class="footer"/><address class="footer"><small>
- Generated by  <a href="http://www.doxygen.org/index.html">
- <img class="footer" src="doxygen.png" alt="doxygen"/>
- </a> 1.8.13
- </small></address>
- </body>
- </html>
|