Coder Social home page Coder Social logo

janphoffmann / interruptedbutton Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 29 KB

Yet another Button Library this time for ESP32 Arduino IDE with GPIO Interrupt and Timer Interrupt for debounce

License: GNU General Public License v3.0

C++ 100.00%
button debounce esp32 hardware-interrupts interrupt timer timer-interrupt aduino-ide esp32-arduino

interruptedbutton's Introduction

InterruptedButton

Yet another Button Library this time for ESP32 Arduino IDE with GPIO Interrupt and Timer Interrupt for debounce

This library is using the interrupt functionality of ESP32s GPIOs.
The debounce functionality is using the ESP32s HardwareTimer 2 , so there is no stupid polling or millis() timekeeping.

Have a look at the example file.

The Callback functionality is not a must use! The nice part of it is, you can use delay() in it how much you like because it's not running in the actual ISR.

The only Catch is, that you have to call the run() function in order to update the Callbacks.
Good thing though: the run() functions return true if the button was pressed and false if not.

Basic usage is like this:

//include the library
#include "myButton.h"

//define some Pins if you like
int FirstPin = 32;

//Button Definitions, no Arguments needed.
myButton FirstButton;

//callback function
void doSth(void* arg, myButton* Button){
  Serial.printf("This is Pin %d",Button->_PinNo);
}
// in setup() function:
void setup() {
  //Begin Functions
  //Sytax: myButton::begin(int Pin, int PinMode, uint64_t DebounceTime [default = 0.5s])
  FirstButton.begin(FirstPin, INPUT_PULLUP);
  //attatch Callback function
  FirstButton.onButtonPress(doSth);

  Serial.begin(115200);
}

// in loop function
void loop() {
  //Run() functions for every Button needed, so you can do as much delay() in the above callback functions as you like ;)
  FirstButton.run();
  // the run() functions return true, if the button was pressed and false, if not...
  if(FirstButton.run()) Serial.println("To use Callbacks , or not to use Callbacks");
}

interruptedbutton's People

Contributors

janphoffmann avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.