Coder Social home page Coder Social logo

tomasz90 / two-buttons-interface Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 21 KB

Two Buttons Interface for embedded devices

License: MIT License

C++ 84.95% C 15.05%
debounce debounce-button debounce-input button-interface esp32-debouncer esp32-interface

two-buttons-interface's Introduction

Two Buttons Interface

Library handles events when pressing buttons. It supports single clicks, simultaneous clicks and long simultaneous clicks of two buttons. It also contains debouncer. It is useful to create simple projects with graphical interface when buttons are used to navigate through a menu. I was not able to find similar library (that handles simultaneous clicks) so I created this one.

Set up is very simple just create two button objects - they need a pin number and mode IN_PULLUP or IN_PULLDOWN - this is based on your wiring, if you connect button to 3.3V - then IN_PULLDOWN, when to ground then IN_PULLUP.

Then buttons need to be passed to ButtonHandler, you also need to create callbacks for actions pressed1, pressed2, pressedBoth. Inside loop buttonhandler will be listening for button events. Additionally, user can specify different than default debounce time.

Same example in dir examples.

PLEASE NOTE: actual callbacks are executed when button is released - this is necessary to be able to handle simultanous click.

#define NEXT_BUTTON 12
#define PREVIOUS_BUTTON 13

Button button1(PREVIOUS_BUTTON, IN_PULLDOWN);
Button button2(NEXT_BUTTON, IN_PULLDOWN);

ButtonsHandler buttonsHandler(button1, button2);

void pressed1() { Serial.println("Button1 pressed"); }

void pressed2() { Serial.println("Button2 pressed"); }

void pressedBoth() { Serial.println("Both pressed"); }

void pressedBothLong() { Serial.println("Both Long pressed"); }


void setup() {
    Serial.begin(115200);
    buttonsHandler.setCallbacks(pressed1,pressed2,pressedBoth,pressedBothLong);
}


void loop() {
    buttonsHandler.poll();
}

Additionally user can define debounce time and long press time:

    buttonsHandler.setDebounceTime(20);
    buttonsHandler.setLongPressTime(1000);

two-buttons-interface's People

Contributors

tomasz90 avatar

Watchers

 avatar  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.