One button at a time
Press two buttons together and BTNS reads exactly what the one nearer it in the ladder reads alone. The other is invisible, and no sketch can find it. So the six buttons are one choice of six, not six separate buttons: U11 beats everything, U6 beats nothing.
The nearer one wins
Press U8 and U6 together. U8 joins its point of the chain to 3V3, four resistors from BTNS. U6 joins a point further along to 3V3 as well. But the point where U8 is already sits at 3V3, and U6's point is joined to it only through R13, with 3V3 at both ends. No current flows through R13, so U6 changes nothing. BTNS reads a fifth of 3V3, exactly as for U8 alone.
The same holds for any pair, and for three or more: whichever pressed button is nearest BTNS holds its point at 3V3, and everything beyond it is shut out. In order, from the button that beats all the others to the one that beats none:
U11, U10, U5, U7, U8, U6.
Not a sketch problem
The reading with U8 and U6 held is the same number as U8 alone, to the millivolt. There is nothing left in it for a sketch to find, so no clever code can recover the second button. That is the price of six buttons on one pin, and the reason a game pad with a diagonal on its buttons needs a pin per button.
In practice it costs less than it sounds:
- Use the stick for anything that moves in two directions at once. X and Y are separate pins and read together.
- Use KEY as the second button. It is its own digital pin, so a click reads alongside anything on BTNS.
- Give U11 a job that is never combined with another press, because while it is held no other button reads at all.
Steering a dot is laid out that way: the stick moves, the diamond nudges one step at a time, KEY drops a mark, and U11 starts again.
When it does not work
That is the ladder. The one nearer BTNS wins: U5 over U7, U7 over U8, U8 over U6. For diagonals, use the stick, which reads both axes at once, and keep the diamond for single steps.
U11 joins BTNS straight to 3V3, the top of the scale, and nothing pressed with it can change that. Give U11 a job you would never hold down while pressing something else, such as a reset or a pause.
Not from BTNS. Use KEY, the click under the stick, which is its own digital pin and reads alongside any button. For more than that, add another button block on pins of its own.
Six wires and a sketch that prints the stick, the click and the button.
The first read →Edit this page — content/books/slim-joystick/one-button-at-a-time.mdx
Questions about this product
See what other owners have asked, and read their solutions.
Slim Joystick
Loading discussions…
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.