This seems quite interesting, can you explain more about this circuit. I've seen this kind of setup for numeric key matrices and I am curious on how to read the values.
Turn on the internal pull-up resistor and you have a voltage divider that depends on which button is pressed. Use analogRead() to read the values.
Yea you read the values with a Analog pin, a simple analog read example will do the work,
and you will get in the serial monitor the values from 0 to 1024. More buttors you will have
the closer the values will be for example.
(You press each button apart you will get a value)
Button 1: 248
Button 2: 475
Button 3: 683
Button 4: 834
Button 5: 987
With that values you can code a if and get the output you want.
The values depend on the resistors and how many buttons you press a time.
(Note: You will not get the same value for button 2 if you press both buttons 1 and 2 in the same time
they will be combined)
This example is good and accurate only if you press a single button a time.
You can connect them over I2C, SPI, the Serial Pins, Software Serial or bit-banging with GPIO pins.
YOU have to write the code that decides how they communicate and operate with each other.
There is no magic "connect these two pins and use this library" option. YOU have to write it.
Of course, that's a lot of overhead when simple shift register could be used to add more pins.
I never tried I2C connection between 2 ATmegas, I know the code is up to me how exactly they gonna work
but in this case i can imagine only to get the serial monitor data from the one Chip and process them
with the other one.
Like this:
(Sensors, buttons..etc) -> ATmega1 -> Data -> Atmega2 -> OUTPUT -> (Leds, ..etc)