<dlclass="todo"><dt><b><aclass="el"href="todo.html#_todo000001">Todo:</a></b></dt><dd>Make Bounce2 more abstract. Split it from the hardware layer. Remove deboucing code from Bounce2 and make a new Debounce class from that code. Bounce2 should extend Debounce. </dd></dl>
<p>Simple example of the <aclass="el"href="class_bounce.html"title="The Debouncer:Bounce class. Links the Deboucing class to a hardware pin. ">Bounce</a> library that switches the debug LED when a button is pressed.</p>
<divclass="fragment"><divclass="line"></div><divclass="line">/* </div><divclass="line"> DESCRIPTION</div><divclass="line"> ====================</div><divclass="line"> Simple example of the Bounce library that switches the debug LED when a button is pressed.</div><divclass="line"> */</div><divclass="line">// Include the Bounce2 library found here :</div><divclass="line">// https://github.com/thomasfredericks/Bounce2</div><divclass="line">#include <Bounce2.h></div><divclass="line"></div><divclass="line">#define BUTTON_PIN 2</div><divclass="line">#define LED_PIN 13</div><divclass="line"></div><divclass="line">// Instantiate a Bounce object</div><divclass="line">Bounce debouncer = Bounce(); </div><divclass="line"></div><divclass="line">void setup() {</div><divclass="line"></div><divclass="line"> // Setup the button with an internal pull-up :</div><divclass="line"> pinMode(BUTTON_PIN,INPUT_PULLUP);</div><divclass="line"></div><divclass="line"> // After setting up the button, setup the Bounce instance :</div><divclass="line"> debouncer.attach(BUTTON_PIN);</div><divclass="line"> debouncer.interval(5); // interval in ms</div><divclass="line"></div><divclass="line"> //Setup the LED :</div><divclass="line"> pinMode(LED_PIN,OUTPUT);</div><divclass="line"></div><divclass="line">}</div><divclass="line"></div><divclass="line">void loop() {</div><divclass="line"> // Update the Bounce instance :</div><divclass="line"> debouncer.update();</div><divclass="line"></div><divclass="line"> // Get the updated value :</div><divclass="line"> int value = debouncer.read();</div><divclass="line"></div><divclass="line"> // Turn on or off the LED as determined by the state :</div><divclass="line"> if ( value == LOW ) {</div><divclass="line"> digitalWrite(LED_PIN, HIGH );</div><divclass="line"> } </div><divclass="line"> else {</div><divclass="line"> digitalWrite(LED_PIN, LOW );</div><divclass="line"> }</div><divclass="line"></div><divclass="line">}</div><divclass="line"></div><divclass="line"></div></div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hrclass="footer"/><addressclass="footer"><small>
Generated by  <ahref="http://www.doxygen.org/index.html">