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);
}
}
}
}
}