48 inputs and 48 ouputs with arduino mega

Hi.

I want to make midi controller with arduino. I would like it to have 16 force sensitive resistors and 16 rotary encoders with push buttons and RBG leds.

Is there going to be problems with latency or otherways if I do the following?

-Rotary encoders to digital pins 21-53.
-Rotary encoder push buttons to HC 4067 mux chip and that chip to digital pins 15-20.
-Rotary encoder leds to mux shield and that shield to digital pins 2, 4, 6 and 7 and to analog pins 0-2.
-Force sensitive resistors to HC 4067 mux chip and that chip to digital pins 9-14.

Everything will be connected with wires not with those connectors you can see on arduino.(Those connectors will be removed with usb port and power jack.) I will remove everything because I want my electronics to fit in as flat as possible.

Any tips how to construct the code is welcome as I am not pro coder.

-Rotary encoders to digital pins 21-53.

21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
51, 52, 53

33 pins for 16 encoders?

Encoders are usually read using interrupts. The Mega does not have 32 external interrupt pins.

Is there going to be problems with latency

Most likely, along with missed encoder changes.

I am sorry for my mathematical error there.

I was thinking that I might need more interrupt pins but was not sure.

It seems like I have to think about something else.

Thank you for your help.

You might investigate an MCP23017 to support many interrupts. Datasheet states all sixteen I/O pins can detect interrupts and they can be joined to provide one signal to a controller.

Pin change interrupts monitor banks of 8 pins and may work for the rotary encoders - unless the pulses come in too fast. Should be available for all pins.

dougp:
Datasheet states all sixteen I/O pins can detect interrupts and they can be joined to provide one signal to a controller.

You have two interrupt outputs on that chip (which in turn should trigger an interrupt on the Arduino), which tell on which group of 8 pins an interrupt occurred. After that you have to read those pins (all 8 can be read in one go) and figure out which one was triggered.

Similar to the AVRs pin change interrupts.

I'd recommend an Arduino Due. It has external interrupts on all digital pins, has the same form factor as the Mega, and supports MIDI over USB natively.

Pieter