I need to read the input from 8 different push buttons on an ATtiny microcontroller. After researching how to do this with the least number of pins, I found out about using a voltage divider with resistors and reading the input voltage with an analog pin.
This seems to work fine "in the lab", as I'm getting a constant voltage from a power supply or an Arduino.
Now, I was thinking that, since the analog reading is based on the voltage provided, if this voltage changes then the reading won't be the same anymore, right?
I do all my schematics and code using a 3.3 V input, but then I want the final project to run on two 1.5 V batteries connected in series (~3 V). The voltage will be changing depending on the charge of the batteries, so my code won't be able to register the button presses properly anymore.
If this is the case, what solutions or alternative methods can I implement? I don't think using one pin per button is feasible.