How to monitor state of 50 Digital Inputs

Hello. Good day.

I have a specific project need and I spent the past couple of days searching on forum, blogs, etc and I’m still not clear if that’s feasible to do with Arduino or not.

I need to monitor the state of ~50 digital inputs and trigger an action when any of the pin changes either from 0 to 1 or from 1 to 0, pretty much the same as pin state interrupt works, only difference is that I need to “listen” to ~50 pins, instead of just a couple. I must be able to identify what pin triggered the action and what was the change (0->1 or 1->0).

My initial idea is to use a MEGA 2560 and have a group of 50 “if” statements on the main loop comparing the previous state or each pin (stored in individual variables) with the current one and triggering the corresponding action if something changed.

I’d like to hear from the experts here what would be a more elegant or smarter/faster way to accomplishing this.

I’m eager to receive your feedback.

Thank you.

I would look at https://www.sparkfun.com/products/13601. These boards can handle up to 16 inputs. They connect over I2C to the processor and each has it’s own I2C address. The interesting part is that each board has an INT-line which will trigger low when any of the 16 inputs change. The processor only has to monitor the 4 INT - inputs and then perform an action to read the status from the right board. Much easier code to program, maintain and in case of issues to debug.

Regards, Paul