Matrixing lots of I/O

I'm starting on a project (a tally light matrix for a video switching system) that will require routing lots of switch inputs (32) to lots of digital outputs (64+). I have already found that the MCP 23017 will be good for expanding the I/O lines available to the Arduino. What I am tring to figure out is how to best handle the code portion.

What I'm trying to accomplish is using the inputs to activate 1 or more outputs. The input to output mapping would be static, only needing to change occasionally. I've already done a simple test using a couple of inputs & outputs, and a series of IF/ELSE statements.

What I would like to find out is if this is the most efficient way to accomplish this, or if there are better methods. Once I have this together, I will want to look at a way of reconfiguring the mapping easily, so I want to get off to a good start, in the right direction.

Thanks for the help, Dave

Of course, you should store the desired output states as the bits of a larger variable, ie B10101010 would be every other output turned on. Then you can write that byte the the GPIO register to set the outputs.

If you can arrange the hardware so that the output lines are in the same order as the input lines, then you could just read a byte from the inputs and push that same byte to the outputs. But you can't reconfigure that.

Otherwise, just store your mapping in an array, where each entry in the array specifies the input line associated with an output. Ie., {3, 7, 9} specifies that output 0 follows input 3, output 1 follows input 7, etc.

In your loop, have a routine that cycles through each output and sets the appropriate bit based on the state of the input. It will be much more efficient to read all the inputs first, then set the output bits in your variable, then write the outputs to the MCP. Otherwise you would be reading and writing to the MCP separately for every input and output.