Yes, that seems like a good idea, but anyways I'm going to propose an alternative that just came to my mind.
If you have access to logic gates you could map many n
buttons to ceil(log2(n + 1))
pins through boolean logic. As an example, if you have 4 buttons, but only 2 pins you can create a configuration like this:
Buttons | Pins
---- | --
0123 | 01
---- | --
0001 | 00
0010 | 01
0100 | 10
1000 | 11
That is, button0
pressed should have pin0
and pin1
low; button1
, pin0
low and pin1
high; button2
, pin0
high an pin1
low; and button3
, pin0
and pin1
high.
From this the following boolean expressions would arise
pin0 = button2 OR button3
pin1 = button1 OR button3
A mapping of 4 buttons to 2 pins could thus be realized with only 2 OR gates. You would need an additional pin and some additional logic, though, for indicating whether any button is being pressed at all.
Of course, there will still be problems if several buttons are pressed simultaneously.
Also, if you will still be going with the resistor approach, consider using larger values on the resistors other that 100 ohms since 5 V through resistors on the order of 100s of ohms would yield a current on the order of 10s of mA which is kind of unnecessarily high. I guess more reasonable values would be 10k Ohm or 47k Ohm.