array pulling everything high

Hi

I have created this project that takes an input and pulls several outputs high. I built it with one input switch. I am now adding a second switch which should only pull one pin high. But all the pins are being pulled up. I am sure that buttonstate needs to be an array but I am not sure how to work it into the loop. thanks for any pointers

const int zone2[] = {11,12,13,0};
const int zone3[] = {11,0};

const int * zones[]={zone2,zone3};

int buttonState = 0;         // variable for reading the pushbutton status

void setup() 
{
  //initialize the output pins that will control lights
  pinMode(11, OUTPUT);//need to loop through all arrays setting up pins as output      
  pinMode(12, OUTPUT);
  pinMode(13,OUTPUT);
  
  // initialize the pushbutton pin as an input:
 //set all light switches to the same block ie pins 2 - 10
  
  byte i; 
  
  //this loop sets all the pins as inputs
  for (i=2;i< 4;i++) {
    pinMode(i, INPUT);  
    digitalWrite(i,HIGH);  // this makes it connect to the internal resistor
  }
}

void loop()
{
  // read the state of the pushbutton value:
  byte myInput =2;

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:  
 
  for (myInput = 2;myInput<4; myInput++) {
  buttonState = digitalRead(myInput);// buttonstate needs to be an array put inside z loop if buttonstate[z+2]== high
    
    int ArrayCount;
    
    int arrayPosition;
    for (int z = 0; z < 2; ++z) 
      {
        for (arrayPosition = 0;zones[z][arrayPosition] ; arrayPosition++)
          {
            if (buttonState == HIGH) {     
              // turn LED on:    
              digitalWrite(zones[z][arrayPosition],HIGH); 
              } 
            else {
            // turn LED off;
              digitalWrite(zones[z][arrayPosition],LOW);
              }
          } 
      }
  }
}

I'm not sure I understand your question... first, let's get the terminology right: "pulling" a pin means connecting it to a pull-up or pull-down resistor; and you usually do that for input pins only. When it's an output pin, you simply "set" it HIGH or LOW.

Now, the internal resistors in the Arduino are pull-up, meaning that if you enable them, input will read HIGH by default, unless your switch connects it directly to GND.

Sorry I mean the output pins are being pulled high.

I am building a lighting solution so one switch controls one group of lights another switch another.

When I wrote this with a single switch wired to input2, it would control zone2.

I am expanding the solution, adding another input wired to 3 and controlling zone3. Zone3 should only turn one light on or off. However it's controlling all the lights connected to zones3.

Consider this line:

for (arrayPosition = 0;zones[z][arrayPosition] ; arrayPosition++)

This loop goes over all the output pins in zone z. There's no condition to stop it if you want just one LED to light up.

yes, the next block checks the state the variable buttonstate this decides if the pins should be high or low. I believe that button state needs to be changed to an array and holding the high/low of each input pin. I dont know how to work into the loop correctly though.

 if (buttonState == HIGH) {     
              // turn LED on:    
              digitalWrite(zones[z][arrayPosition],HIGH); 
              } 
            else {
            // turn LED off;
              digitalWrite(zones[z][arrayPosition],LOW);
              }

There are many ways to do this, but I think you should think forward and decide what your finished system will do, then build the most appropriate code.

You can have two separate arrays (e.g. zone2_pins, zone2_states) or, if you know how, put the data for each LED in a struct. Then, decide how you want the button press to effect the states.