If you need just the encoders and a couple of push buttons, you might get away with just polling them for changes. If there's much other stuff going on in your code, you'll have to resort to interrupts, which is much more tricky.
These examples could prove helpful:
- Control Surface: NoteButton.ino
-
Control Surface: RotaryEncoder.ino
(If you're using a DIN connector, useHardwareSerialMIDI_Interface
instead ofUSBMIDI_Interface
, see Control Surface: MIDI Tutorial).
If you want to go the interrupt route, see:
-
Control surface + library encoder = the full adventure with Presonus studio one - #58 by PieterP
Other topic where someone tried to use 20 encoders with an Arduino Mega, with code (no idea if they managed to get it working reliably in the end) -
Midi controller with encoders
Another topic with discussion about using many encoders with an Arduino Mega (IIRC, the author ended up switching to a Teensy) - Control Surface: Pin-Change-Interrupt-Encoders.ino
- Control Surface: Timer-Interrupt-Encoders.ino