rlogiacco / analogbuttons Goto Github PK
View Code? Open in Web Editor NEWArduino library to wire multiple buttons to one single analog pin
License: GNU Lesser General Public License v3.0
Arduino library to wire multiple buttons to one single analog pin
License: GNU Lesser General Public License v3.0
Hello,
I try to use the new version from a long time and hd now understood what is my issue!
I con't configure the buttons!
So i have just changed into your example the configure fonction like that:
void configure() {
int val = analogRead(ANALOG_PIN);
Serial.println(val);
delay(1000);
}
Now , i can configure the buttons and play with !!!
I'm using a fairly common LCD + Button shield designed by DFRobot and available many other places. It has 5 buttons on A0 analog pin.
The problem I seem to be having is with the Right button not firing it's press or hold functions.
I believe the problem is because the right button has an ADC reading of 0 (ZERO).
When it gets to the following line:
if (reading >= buttons[i].value - margin && reading <= buttons[i].value + margin) {
The comparison fails with the following values being tested
reading:0
buttons[i].value - margin : 65526
buttons[i].value + margin : 10
By changing a couple of variable definitions to support unsigned integers seems to fix it.
Change the following lines, sorry I don't know how to make a pull request :(
void AnalogButtons::check() {
/* other misc lines */
uint16_t reading = analogRead(pin);
to
int16_t reading = analogRead(pin);
AND
class Button {
public:
uint16_t value;
to
int16_t value;
I got the following values which fixed my problem.
reading:0
buttons[i].value - margin : -10
buttons[i].value + margin : 10
I'm interested in feedback on this code change, since I'm not much of a C programmer.
Currently there is no proper way to use click and hold callbacks simultaneously.
Click must be triggered on push-up-event.
And, of course, push-down and push-up callbacks must be clearly split.
Hi Roberto,
I already sent you an email (you answered). I am trying to use the AnalogButtons library with the ESP32 board (DOIT devkit 1) but I cannot get a result. I can read the analog values of the different buttons (3) but I cannot get the library to function. I have already used the library with an Arduino Leonardo and the code works perfect.
I am using 3 buttons which give values:
161 - 164
490 - 494
1808 - 1818
I also changed the debounce value 5 - 500
so far no results yet
regards
Henk
Not sure how difficult this would be to implement. Consider this scenario:
A group of 5 buttons, which toggle the values of 5 elements in an array, Array1
If the 5th button is 'long-pressed', it changes the target of the 5 buttons to a different array, Array2
If Button5 is long-pressed again, it switches back to Array1.
Is there currently a way to have Button5 only change the value of the 5th array element upon release of a 'click', so that, for example, if Array1[5] = '1', a long-press of Button5 won't change it back to '0' before (or after) switching to the second array?
If not, would you consider adding that functionality? Very useful for ui/menu type of functions.
Thanks.
EDIT: I was able to mod the library to do this. It's a bit of a hack, but seems to be stable. Also removed the 'repeating hold', since it was not the functionality my project needed. If anyone wants it, 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.