Is it possible to debounce several push buttons connected to a single analog input?
I have searched for guides and they all relate to single button on single input, so I was wondering if anyone has done this and can share how they done it.
Is it possible to debounce several push buttons connected to a single analog input?
I have searched for guides and they all relate to single button on single input, so I was wondering if anyone has done this and can share how they done it.
in general, a single ~10 msec delay whenever there is a change in state of one or more button presses is adequate.
If Reply #1 is not a sufficient answer then a diagram showing how you have everything connected would be a big help. A photo of a simple pencil drawing will be best. See this Simple Image Posting Guide
...R
How, incidentally, are you wiring the buttons. There are a number of different ways and some allow multiple simultaneous presses to be correctly resolved. However, the more buttons you have in a chain, or ladder, the greater is the risk of a misreading through instability in analogRead() / ADC.
Here is one example: Arduino Forum
See also R2R ladder
I have attached a file with the way things are connected.
And yes, I am having alot of issues with misreadings. I do have 13 buttons attached to a single analog input.
Because of my setup I am having issues with debouncing and misreadings. It doesnt bother me that I cannot press two buttons at once, but stability is a must.
I was just wondering if there was a software solution for this, if not I will just use each digital pin to each button, since I am using a MEGA, This is surely solve all these problems.
I believe that you should be treating this as debouncing a single switch on A0 and a single switch on A1.
What is likely to make life difficult for you is a piano keyboard where C is connected to R1 on A0 but C# is connected to R1 on A1. These sorts of inconsistencies can make programming more challenging.
Not to mention that a schematic where component designations are re-used (e.g., R1 appearing twice) is unusual.
You are going to have problems because the input will be floating when none of the contacts is connected to 5 volts.
My mistake, the input will obviously be at ground with no contact closed.
You may be getting problems with poor contact from your stylus, that will make for a very bouncy switch contact.
david_2018:
You are going to have problems because the input will be floating when none of the contacts is connected to 5 volts.My mistake, the input will obviously be at ground with no contact closed.
You may be getting problems with poor contact from your stylus, that will make for a very bouncy switch contact.
Yes you are right. Since what I am am making is a midi stylohphone, triggering the wrong note is a big problem. I would rather not trigger the note than trigger a different note. That is why I am going to change my setup and connect each key to a single digital input.
The values of the resistors could also be an issue because these determine the spread of analog values you read at points A0 and A1.
You probably need to sample the analog value for a few milliseconds, attempt to determine which key has been pressed, then ignore small changes in that value, waiting for the user to lift the stylus which will cause the analog value to rapidly fall to zero.
It is not a typical debouncing problem because, with a musical instrument, you need to be able to hold the key for varying lengths of time. The debouncing technique of a simple rejection of key strokes for a set number of milliseconds since the last detection won’t work because holding the key pressed for an extended period will result in multiple consecutive detections.
I am already ignoring small changes of A0 and A1. I did not use the map for them. I manually checked the value that each resistor gives me, and with that I add +10 and -10 to create a range. The problem is that I can only have the working range -10 + (A0) <A0 < +10 + (A0). Because of the quantity of buttons used (12) this range is very short. So when the stillus doesnt fully make contact, it goes outside the range.
Thank you all for the suggestions. I actually have enough digital ports available, so I will just use them for this.
Hint: when I implement an analog key set, I identify the nominal 'centre' value for each key, then allow a margin (+/- 5%) so the key is reliable 'read'.
(This has worked on over 100 units with the same 2K2 R-ladder over 4+ years)
No keys closed, or values 'in-between' the defined keys returns a 'NO_KEY' value which is ignored in most cases.
With this approach, debouncing is almost not required, because valid key values are returned, or 'NO_KEY'.
Multiple keys (polyphony) is a slightly different problem, and there are a couple of approaches available.