How to optimize resistor values for reading multiple buttons on a single analog input?

Came up with some code for a project I'm working on that is able to read two buttons for each analog input (and tell if two have been pushed) based on this circuit. It works, but is not really optimized resistors-wise. I've yet to figure out a generalized expression for this type of parallel circuit (thinking one in which I could make it 3, 4, whatever resistors/buttons), which admittedly would be a matter of elegantly combining some algebraic equations. Any thoughts? Here's the rest of my code, FWIW https://github.com/JeremySCook/arduino-experiments/tree/main/MIDI/1-inch-MIDI
GitHub
arduino-experiments/MIDI/1-inch-MIDI at main · JeremySCook/arduino-...
Experiments in Arduino C. Contribute to JeremySCook/arduino-experiments development by creating an account on GitHub.
attachment 0
attachment 1
3 Replies
JeremyCook
JeremyCook5mo ago
BTW, what is the best way to post a bunch of code here? I think there is something with using ` but seems I always get it wrong.
aymen ammari
aymen ammari5mo ago
Why are you using analog signal to read a digital input, you could use '' INPUTPULLUP" or "pulldown" functions and read values only where it's near 0/1 this makes a lot better preformence
JeremyCook
JeremyCook5mo ago
Because I am reading two buttons on each pin. I am using an ATtiny85 and my IO is very limited.
Want results from more Discord servers?
Add your server