Code for MIDI controller doesn't work... help!

Hi guys! I'm working on a MIDI controller based on arduino 2009. I starter programming and everything was fine but now i've a problem/bug i can't fix.

The project is made of: - 5 x 4051 multiplexers for 40 potentiometers - 7 x 4021 shift reg. for 56 buttons and rotary encoders Rotary encoders are connected to 3 pin each. The program should do the rest.

The loop part of my program is doing this:

void loop() { // Buttons Mux // Function that handles digital mux for buttons startReadingButtonMux();

// Pots Mux readPotsMuxValuesArray(); sendPotsMuxValuesArray();

// Rotary encoders handleEncoders();


Very simple: Firts reads the data of mux-buttons, if it's connected to a simple button it fires a midi noteOn. Then reads the potentiometers. Then handles the rotary encoders rading some data stored before by the startReadingButtonMux function.

I attach the code.

The problem is:

Till i have only [u]3[/u] 4051 mux for potentiometers everything works fine. If i add one more 4051 for potentiometers (i have 4 4051) the encoders stop working. It seems like there's a conflict between more than 3 4051 for pots and the rotary encoders handling. If i comment the pots function rotary encoders work fine, if i comment the encoders function potentiometers work fine.

Any idea? Suggestion? Is it possible that arduino can't handle all this data?

When i compile the code, the size is this Binary sketch size: 4854 bytes (of a 14336 byte maximum)

You can have a look at the code here:

Thanks in advance for any help :) g

Can you show us a schematic of your hardware?

i’ll draw it and post it

Hi here's the schematic i made.

What about a problem of memory limit???? Is it possible i'm using all the 1kb of ram?

Is it possible i'm using all the 1kb of ram?

Possibly! Do you need all those arrays in your program to be 'int' or will some of them work with just 'byte' types? That would save some memory, if your code will work with numbers in the range of 0..255.

Yesterday i was doing some test with the Available Memory Function (

I saw that as i was adding items to one array, the memory decerased (from 80 to 72, from 72 to 64 and so on) till the point the arduino was not responding anymore. Serial printing some strange stuff...

So i thinks it's a memory issue

I'll check if i can work on types to save some memory - i'll post the code again. What is worring me is that this is not the definitive project which is supposed to be even larger.

I'm thinking about arduino mega...