Centipede Shield

Having trouble using array's with centipede shield.
Is there a max length, for array in arduino.
Using port 0 (chip1), all input (16), in an array. compiler accepts it as valid,
but nothing works.

const int buttonPin[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; // pushbutton and limit switch pins
int buttonState = 0;// variable for reading the pushbutton status

Wire.begin(); // start I2C
  CS.initialize(); // set all registers to default
  CS.portMode(0, 0b1111111111111111); // set all pins on chip 1 to input
  CS.portMode(1, 0b1111111111111111); // set all pins on chip 0 to output
  CS.portMode(2, 0b0000000000000000);
  CS.portMode(3, 0b0000000000000000);

 CS.pinMode(Relay1, OUTPUT);
  CS.pinMode(Relay2, OUTPUT);
  CS.pinMode(Relay3, OUTPUT);
  CS.pinMode(Relay4, OUTPUT);

 CS.pinMode(sensor1, INPUT); 
  CS.pinMode(sensor2, INPUT);
  CS.pinMode(sensor3, INPUT);
  CS.pinMode(sensor4, INPUT);

/*..Initialize the pushbutton pins as an input..*/
  int x;
  for(int x = 0; x < 15; x++)
    {
    CS.pinMode(buttonPin[x], INPUT);
    }
int x;
  for(int x = 0; x < 15; x++)
  
      {
      buttonState = CS.digitalRead(buttonPin[x]);
      }

if (buttonState == HIGH && buttonPin[x] == 4)//Up Button press
      {    
      CS.digitalWrite(Relay2, RELAY_ON); //Activate Main Pump UP
      }

//Sensor...  
 if (CS.digitalRead(sensor1) == HIGH  && CS.digitalRead(sensor2) == HIGH)
     {
     CS.digitalWrite(Relay1, RELAY_ON);
     }
    else 
     {
     CS.digitalWrite(Relay1, RELAY_OFF);
     }

can't figure it out.

codes to large to post all.

Sensors work perfect with relays, buttons-nothing

Thanks

If you look at your code you'll see that the forum software has scrambled it. To prevent that you need to enclose it in [ code ] [ /code ] tags. (Just click on the # button when you are composing your message.)

You need to post your whole sketch if we're to have any chance of understanding the problem, and you need to be clear about what it's intended to do and how the actual behaviour differs from that.

What also helps for readability of the code is to press CTRL-T (windows) in the IDE . It auto formats code to consequent style.

If the code is too large to post, try to minimize it to a sketch that has the same "bug". That makes it easier to debug too.

Is there a max length, for array in arduino.

No, until RAM is up0.

/*..Initialize the pushbutton pins as an input..*/
  int x;  <<<< does nothing --> remove it 
  for(int x = 0; x < 15; x++) CS.pinMode(buttonPin[x], INPUT);  // simple loops can be on one line
  for(int x = 0; x < 15; x++)
  {
    buttonState = CS.digitalRead(buttonPin[x]);
  }

if (buttonState == HIGH && buttonPin[x] == 4)//Up Button press
      {    
      CS.digitalWrite(Relay2, RELAY_ON); //Activate Main Pump UP
      }

//Sensor...  
 if (CS.digitalRead(sensor1) == HIGH  && CS.digitalRead(sensor2) == HIGH)
     {
     CS.digitalWrite(Relay1, RELAY_ON);
     }
    else 
     {
     CS.digitalWrite(Relay1, RELAY_OFF);
     }

this will not work as buttonstate is overwritten 14 times. so only the state of the last button is remembered
have a look at this

  for(int x = 0; x < 15; x++)
  {
    buttonState = CS.digitalRead(buttonPin[x]);

    if ((buttonState == HIGH) && (buttonPin[x] == 4) )   //Up Button press
    {
      //Activate Main Pump UP    
      CS.digitalWrite(Relay2, RELAY_ON);               
    }
  }

Now the test of buttonstate is within the for loop. Every pin is tested and the value of buttonstate is checked f

See the difference?.

If I remove

int x=0;

I get:
In function 'void loop'():
error: name lookup of 'x' changed for new iso 'for' scoping
error: using obsolete binding at 'x'

Ok, maybe you need to make it,

for(x = 0; x < 15; x++) //NOTE THE CHANGE
  {
    buttonState = CS.digitalRead(buttonPin[x]);

    if ((buttonState == HIGH) && (buttonPin[x] == 4) )   //Up Button press
    {
      //Activate Main Pump UP    
      CS.digitalWrite(Relay2, RELAY_ON);               
    }
  }

declair "int x" outside the function, because I think you might be using "x" in another function, and it might not be able to see the change in "x".

Try that, if it still dont work, post the full code.

HazardsMind:
declair "int x" outside the function, because I think you might be using "x" in another function, and it might not be able to see the change in "x".

Try that, if it still dont work, post the full code.

Better still would be to use a meaningful name for the variable, such as 'checkeachbutton'. When returning to code you wrote a year ago, it might give you a clue as to what it does.

It worked,
I deleted the
int x;
added the extra { } and the extra ( )
and it works beautiful.
Man, electronics today sure are different than in my day,
When you made an AM radio out of a toilet paper roll, some copper wire and a safety pin.
You guys are great,

Thank you very much

It finally sunk into this old mush melon.
I was using the 'for' loop, for each button statement. Which worked
Then I realized you can put all the buttons in one 'for' loop.
And that works, with less problems.