Git Product home page Git Product logo

button's Introduction

Button Library

The Button library for Arduino makes common button tasks simple, filters out mechanical noise, and adds some handy extra features. Solid, dependable, and easy to use button handling is surprisingly difficult, and this library is here to help.

Features

  • De-bouncing. Mechanical buttons physically vibrate - bounce - when they are first pressed or released. This creates spurious state changes that need to be filtered or "de-bounced".

  • Support for pull-up, pull-down, or internal-pull-up configurations.

    • A pull-down button is tied to ground with a resistor (usually about 10k), so the pin is normally LOW. When it closes, the button connects to Vcc and goes HIGH.
    • A pull-up button is normally tied to positive with a resistor (usually 10k), so the pin is normally HIGH. When it closes, the button connects to ground and goes LOW.
    • An internal-pull-up button is just like the pull-up, but uses an internal resistor on the Arduino. These are very convenient to use, as the button just needs to close the connection to ground.
  • Queries for 'press', 'down', and 'held'. Queries are checked after the process() method is called.

    • press() is true when a button is first pressed down.
    • isDown() returns true if the button is down. (When a button is initially pressed both 'press' and 'isDown' will return true. Subsequent queries to a down button result in 'press' false and isDown true.)
    • held() is true if the button has hit the holdThreshold in this loop.
  • Callacks for press, hold, release, and click. Callbacks are called from the process() method. Callbacks are generally easier for more complex button handling (doing something different on hold vs click, for example.)

    • 'press' is called when a button is first pressed.
    • 'click' is called when a button is released, if it wasn't held. 'click' is called after 'release'.
    • 'hold' is called if a button is held down.
    • 'release' is called when the button is released.

Example

Basic Usage

Button button(12);

void setup() {
	Serial.begin(19200);
}

void loop() {
	button.process();
	if (button.uniquePress()) {
		Serial.println("Button pressed.");
	}
}

Callback Usage

ButtonCB button(12);

void onPress(const Button& b){
	Serial.println("Button pressed.");
}

void setup(){
  Serial.begin(19200);
  button.pressHandler(onPress);
}

void loop(){
  button.process();
}

Installing

To download. click the "Download Zip" button in the top right corner, rename the uncompressed folder Button.

Place the Buttons library folder your arduinosketchfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.

Or - even better! - navigate to your arduinosketchfolder/libraries/ folder and clone the repro using git.

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.