madleech / button Goto Github PK
View Code? Open in Web Editor NEWButton is a tiny library to make reading buttons very simple. It handles debouncing automatically, and monitoring of state.
License: MIT License
Button is a tiny library to make reading buttons very simple. It handles debouncing automatically, and monitoring of state.
License: MIT License
Hello, looks like it's possible to softlock button in read() method.
If button changes at time:
millis_max_value - _delay - some_small_value
and doesn't change state back until millis() overflow, then _ignore_until will be almost always bigger then millis().
For an example: if button has been unpressed at millis_max_value - _delay, then state will be saved us unpressed, _ignore_until will be millis_max_value. And right after millis overflow, condition:
if (_ignore_until > millis()) { // ignore any changes during this period }
almost always will be true, and it will lock execution of next condition.
And the only possible exit, except reset, will be holding button down around overflow, hoping not to miss it =)
Hello,
Ensuring that this library can still be compiled (using a continuous integration service such as Travis) could be a nice improvement.
Running some unit tests to ensure that code works correctly could help to ensure that contribution doesn't break anything.
I have been using https://github.com/ianfixes/arduino_ci recently, (this is quite new in Arduino library development). It can help to achieve this.
Are you interested in a pull request to enable such a feature?
If so I can submit it.
Kind regards
Hi, Thanks for maintaining this library! I want to use it in an alarm clock example I'm building for GoodArduinoCode, and for that, I'd need an option to detect long presses and generate repeated events as long as the button is held down.
I imagine something like:
#include <Button.h>
Button hourButton = Button(A0);
void setup() {
Serial.begin(115200);
hourButton.begin();
// After 500ms delay, generate repeated press every 200ms:
hourButton.setRepeat(500, 200);
}
void loop() {
if (hourButton.pressed()) {
Serial.print("Pressed! Repeat count");
Serial.println(hourButton.repeatCount());
}
if (hourButton.release()) {
Serial.println("Released!");
}
}
So if you press the button, hold it down for 1 second, and release, you'll see something like:
[0000] Pressed! Repeat count: 0
[0500] Pressed! Repeat count: 1
[0700] Pressed! Repeat count: 2
[0900] Pressed! Repeat count: 3
[1000] Release
(the numbers in the square brackets are just the milliseconds since the button was pressed).
If you are interested, I can also send a PullRequest which adds this functionality, simply let me know.
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.