Giter Site home page Giter Site logo

dlloydev / toggle Goto Github PK

View Code? Open in Web Editor NEW
11.0 11.0 2.0 112 KB

Arduino button debounce library for various switch types, port expanders and other 8-bit data sources. Fast and robust debounce algorithm.

License: MIT License

C++ 100.00%
arduino debounce debounce-button debounce-library esp32 limit-switch microswitch pushbutton sp3t spdt spst switch tactile-switches toggle toggle-switch

toggle's People

Contributors

dlloydev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

toggle's Issues

Possible conflict with DallasTemperature?

I've used your excellent Toggle library in other projects successfully. But after adding it to my current project it fails to recognise 'short' button presses, i.e. those delivering lows under 200 ms. It does recognise the 'long' button presses ( > 500 ms).

This conflict over resources, if that's what it is, appears to be with the DallasTemperature library. Because if I comment out its statement
// sensors.requestTemperatures();
then your short presses are correctly detected.

I was depending on Toggle so any advice you can offer would be appreciated please. I'm not a C/C++ programmer, so ideally not in over-technical terms!

challenge with enum value and FastLed library

you are using this enum

enum CLICK : uint16_t {FAST = 200, DONE = 500};

challenge is that the fastLed library is also using DONE for a #define

so if you try to compile

#include <FastLED.h>
#include <Toggle.h>

void setup() {}
void loop() {}

the compiler will complain about the double definition

first it's a cryptic

~/Documents/Arduino/libraries/FastLED/src/platforms/avr/clockless_trinket.h:308:14: error: expected identifier before 'asm'
 #define DONE asm __volatile__("2:" ASM_VARS );
              ^

but then everything is revealed

~/Documents/Arduino/libraries/Toggle/src/Toggle.h:50:40: note: in expansion of macro 'DONE'
     enum CLICK : uint16_t {FAST = 200, DONE = 500};
                                        ^~~~

I guess the easiest fix is to change the enum's keyword or create a private namespace for your library (or change the fasted library and its poor choice of using #define...)

Triggering on first push

I have a button attached to my esp32.
And the first push is triggering the pressedfor method

#define FR_PIN  36
#define FR_PIN_FIRST_CHECK_INTERVAL_MS 10000

Toggle button(FR_PIN);

void setup(){
    Serial.begin(115200);
    button.begin(FR_PIN);
}

void loop(){
    button.poll();
    if (button.onPress()) {
          Serial.printf("[FACTORY] - Waiting for reset.\n");
    }
    if (button.onRelease()) {
          Serial.printf("[FACTORY] - Reset aborted.\n");
    }
    if (button.pressedFor(FR_PIN_FIRST_CHECK_INTERVAL_MS)) {
          Serial.printf("[FACTORY] - Reset initiated.\n");
    }
}

Debug on just a single push first time

[FACTORY] - Waiting for reset.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset initiated.
[FACTORY] - Reset aborted.

Debug on a single push the 2nd time

[FACTORY] - Waiting for reset.
[FACTORY] - Reset aborted.

What is the problem? Should i reset some kind of a timer?

pressedFor not true only once

the example

if (myInput.pressedFor(500)) {
   // true (once only) if button has been pressed for 500ms
}

does not seem to work. I get repeated output with this code in Wokwi

#include <Toggle.h>                         // https://github.com/Dlloydev/Toggle

Toggle sw;
const unsigned long longPressDelay = 3000ul;

void setup() {
  Serial.begin(115200);
  sw.begin(3);
  Serial.println("READY");
}

void loop() {
  sw.poll();
  if (sw.pressedFor(longPressDelay)) Serial.println("LONG PRESS");
}

is that a wokwi issue ?

what code would let me check for both short and long press on a button? checking for onPress() will not work with pressedFor() apparently.

clarify usage of Toggle::inputMode::input_pulldown versus setInverted

Hi

it's unclear how you would use setInputMode(Toggle::inputMode::input_pulldown) versus setInputInvert(true)

working exemple here with setInputInvert and messing around with the pin state after the begin (which means I overwrite likely what the class has done to the pin which requires intimate knowledge of the library to know in which order to do things)

https://wokwi.com/projects/347839208139784788

Request:

  • how would you use setInputMode() and not have to mess around in the code with pinMode?
  • improvement: possibility to establish the inputMode at constructor level

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.