Multiplexer with interrupts

I have a project where there are 16 buttons that can be pressed at anytime to trigger an event. Initially, I was going to use an interrupt for each button, but there aren't enough on the Mega. I read the other way to get more interrupt pins, but I'm not inclined to go to down that road.

I've been reading about multiplexers and I think it is just what I need. My idea is that the 16 multiplexer inputs ( this one http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=ADG406BNZ-ND for example) will be connected to the button outputs. However, I'm a little confused on how the multiplexer and arduino will know which button was pressed.

I understand that the 4 pins on the multiplexer need instruction from Arduino on which pin to read. However, I don't know which pin needs read ahead of time. Is there a way for the multiplexer to recognize which pin went high from a button push some how? Or should I be looking in another direction to achieve what I'm after.

The Atmel has a "pin change interrupt" which watches all 8 bits of a port. Not sure how to code that with the Arduino, but I'm pretty sure it has been mentioned on the forums before.

You could probably use some diodes and a "wired-OR" configuration on a single interrupt, but I haven't really thought that one through...

-j

You could probably use some diodes and a "wired-OR" configuration on a single interrupt, but I haven't really thought that one through...

That's how I would do it. Wire each of the 16 switchs to ground and to 16 digital input pins with their internal pull-ups enabled. Then wire a diode from each switch to one interrupt pin which also has it's internal pull-up enabled (anode end of the diodes to the interrupt pin). Enable the interrupt on falling. When the interrupt is triggered (by any of the 16 switches) the ISR function would then perform a digital read on the 16 switch input pins to determine which caused the interrupt.

Lefty

If you use a MCP23S17 then that gives you 16 I/O pins. There is also an interrupt output that gets triggered if any of the inputs change. Then all the ISR has to do is to read the chip to see which one changed.

Thanks for the replies everyone. I think the MCP23S17 is just what I need.

;D