Giter VIP home page Giter VIP logo

smartbutton's Introduction

SmartButton Library

SmartButton Library is used for handling various button events. It supports button press, release, multiple click and button hold events. Library is implemented in C++ with build-in Arduino port, but it is easy to port to different architecture.

Features

  • asynchronous non-blocking API based on events callbacks
  • hardware independent high-level architecture
  • works well with digital, analogs and other signal input backends
  • easy to use with Arduino boards
  • unlimited number of buttons
  • support multi-click events
  • support press and release events
  • support hold and long-hold events
  • support auto-repeat events during hold and long-hold
  • build-in debounce algorithm
  • configurable timeouts

Changelog

2020.08.12 - 0.3.0

  • hold auto-repeat periodic events added

2020.08.10 - 0.2.0

  • optional initialization by object-interface added
  • optional initialization by bool-pointer added
  • optional context passing added

Example

Single and double click example:

#include <Arduino.h>
#include <SmartButton.h>

constexpr int BUTTON_PIN = 2;
constexpr int LED_PIN = 13;

using namespace smartbutton;

SmartButton button(BUTTON_PIN, SmartButton::InputType::NORMAL_HIGH);

void setup()
{
    pinMode(LED_PIN, OUTPUT);           // Digital output for led
    pinMode(BUTTON_PIN, INPUT_PULLUP);  // Digital input with pull-up resistors (normal high)

    // Initialize and register smart button
    button.begin([] (SmartButton *button, SmartButton::Event event, int clickCounter)
    {
        if (event == SmartButton::Event::CLICK) {   // Click event handler
            if (clickCounter == 1) {
                digitalWrite(LED_PIN, LOW);         // Single click will turn led off
            } else if (clickCounter == 2) {
                digitalWrite(LED_PIN, HIGH);        // Double click will turn led on
            }
        }
    });
}

void loop()
{
    SmartButton::service();   // Asynchronous service routine, should be called periodically
}

smartbutton's People

Contributors

marcinbor85 avatar

Watchers

James Cloos avatar

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.