right code for arduino mega 2560, midi mapping in DAW is fluctuating

I am trying to make a midi controller with 16 potentiometers, push buttons and sensors with arduino mega 2560. I have been able to use usb midi so I dont need 5 pin din IO. I have spent days and night looking for right codes for arduino mega 2560 to use potentiometers, buttons, multiplexer and sensors but i have got no clue so far. i am kinda frustrated. all i got is code for uno and the site says they have done direct port manipulation for uno specially and I dont know how to change codeforunotto mega 2560 or what should I do. so still if i upload the code then i have a lot of fluctuations problems due to which when i try to map a knob in DAW, it automatically takes values without me touching the controller and keeps changing. I am looking for help and i really hope you guys expertise can help me out. I would really appreciate if you could send me a link with the code that supports mega 2560 and some notes on how to manipulate basic codes as per my required numbers of buttons and controllers. thank you .

I have spent days and night looking for right codes for arduino mega 2560 to use potentiometers, buttons, multiplexer and sensors but i have got no clue so far.

Your time would have been much better spent learning to write code.

I dont know how to change codeforunotto mega 2560

See:-
Direct port mapping

it automatically takes values without me touching the controller and keeps changing.

Probably because it is poor code. An analogue reading will always fluctuate by a small amount. What the code needs to do is to remember the last number it got when it sent the last MIDI message for that pot, and only send a new message when the pot reading is different by a certain amount, you could put this amount into a variable called say threshold.
So the code fragment would look something like:-

if(abs(analogRead(pin) - lastReadingForThisPin) > threshold ) {
   // send the value given by the new pot reading
}