dlloydev / toggle Goto Github PK
View Code? Open in Web Editor NEWArduino button debounce library for various switch types, port expanders and other 8-bit data sources. Fast and robust debounce algorithm.
License: MIT License
Arduino button debounce library for various switch types, port expanders and other 8-bit data sources. Fast and robust debounce algorithm.
License: MIT License
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!
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...)
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?
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.
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:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.