Coder Social home page Coder Social logo

debounce's Introduction

Debounce

Really small Arduino library for button Debouncing. It's basically the Debounce example found on http://arduino.cc/en/Tutorial/Debounce wrapped as a library.

Really easy to use, with examples included.

Tested on an Arduino Due only.

Instructions

Include the library in your sketch:

#include <Debounce.h>

Constructor

Use one of this constructors, the default delay works great and is the recommended constructor.

Debounce Button With Default Delay

Create a Debounce object for your button, with a default delay of 50ms:

Debounce Button(4); // 4 is the pin, could be a variable too.

Debounce Button With a Custom Delay

Create a Debounce object for your button, with a custom delay:

Debounce Button(4, 80); // 4 is the pin, 80 is the delay, in ms.

Debounce Button With a Custom Delay and INPUT_PULLUP

Create a Debounce object for your button, with a custom delay and INPUT_PULLUP:

Debounce Button(4, 80, true); // 4 is the pin, 80 is the delay in ms, true for INPUT_PULLUP.

Note: This constructor will change the button input pin to INPUT_PULLUP.

Functions

Debounce has only a few easy to use functions.

read()

Inside your code, Button.read(); reads your button state and returns HIGH or LOW after debouncing it. It should always return HIGH when the button is pressed, and LOW otherwise.

This will turn the led on pin 13 ON when the button is pressed and debounced, it stays on until you release the button.

void loop() {
  digitalWrite(13, Button.read());
}

count()

Returns the counter of changes ocurred to the button. The counter will increase by 1 each time you press the button for longer than the debounce time. It will also increase by 1 when you release the button after it was debounced.

This will turn the led only when the button has been pressed and released 5 times. Turns Off after another 5 press-and-releases.

if (Button.count() == 10) {
  digitalWrite(13, HIGH);
} else {
  digitalWrite(13, LOW);
}

resetCount()

Resets the counter for the button changes.

debounce's People

Contributors

pccr10001 avatar per1234 avatar tymec avatar wkoch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

debounce's Issues

Examples don't match with invert

With the addition of the invert, the examples with a custom delay no longer work as this has become ambiguous. When a custom delay is wanted, I guess this makes the extra parameters required?

From one of the examples:
Debounce Button2(button2, 70); // Button2 debounced, custom 70ms delay.
This now generates an error:
call of overloaded 'Debounce(byte&, int)' is ambiguous

This would work though:
Debounce Button2(button2, 70, false, false);

Button Off Time (High) is same as delay time

Debounce Button1(button1, 30000,false,false);
//if delay is 30 seconds then led will turn on after 30 seconds but it will remain on for another 30 seconds after button is release.

INPUT_PULLUP is inconstant to the readme

In the readme, it appears that only if you put the 3rd variable in the Debounce Button(2,80,true) that it appears that the pull_down is default, where the default is true.

It might be best to change Debounce.h from
25 Debounce(byte button, unsigned long delay = 50, boolean pullup = true);

to
25 Debounce(byte button, unsigned long delay = 50, boolean pullup = false);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.