ok would you quickly knock an example sketch up to show me this compared to what i have done.
#define A_light 13 // Light A on pin 13
#define B_light 12 // Light B on pin 12
#define C_light 11 // Light C on pin 11
#define D_light 10 // Light D on pin 10
becomes
const int lightPins[] = {13, 12, 11, 10};
#define A_light_button 1// Light A button
#define B_light_button 2// Light B button
#define C_light_button 3// Light C button
#define D_light_button 4// Light D button
becomes
const int switchPins[] = {1, 2, 3, 4};
int buttonA = 0;
int buttonB = 0; // val will be used to store the
int buttonC = 0; // state of the input pin
int buttonD = 0;
becomes
int states[4];
void setup() {
pinMode(A_light, OUTPUT);
pinMode(B_light, OUTPUT); //Setting the digital
pinMode(C_light, OUTPUT); // pin's as output
pinMode(D_light, OUTPUT);
pinMode(time_button, INPUT);
pinMode(A_light_button, INPUT);
pinMode(B_light_button, INPUT);
pinMode(C_light_button, INPUT); // Setting as an input
pinMode(D_light_button, INPUT);
}
becomes
void setup()
{
for(byte b=0; b<4; b++)
{
pinMode(switchPins[i], INPUT);
pinMode(lightPins[i], OUTPUT);
}
pinMode(time_button, INPUT);
}
Now, you try making the changes to loop(). Read the states in a loop. Create a function to use the state of one pin to toggle the LED on another pin. The function will look like:
void toggleWithLongDelay(int switchState, int lightPin, bool longDelay)
{
// Do stuff here...
}
The call will look like
toggleWithLongDelay(state[i], lightPins[i], timeButton == HIGH);
That call will be made in a loop, obviously.