Well before proceeding with rest of the discussion in posts below
I would like to introduce the very first level of study
Here I tested it on 2 arrays of LEDs where each array has 4 set of LEDs
Applying the counter to array 1 selects an LED from pin 6 to pin 9 as mentioned in code below
and applying counter for array to selects LEDs from 10 to 13
For array 1
The selected LED gets triggered with Pin 22
For array 2
The selected LED gets triggered with Pin 23
All set !!!
Now as per the requirement with multiple variables to serve for different counters
the system is work well for 2 functions but . . .
A small issue is here : -
From both the arrays of LED packs as per rule we have positions 0,1,2,3
But at startup
The LED at the 1th position gets light Up on triggering
and counter starts from 1 then 2 then 3 but not from the 0th position
This thing happens with both the counters
I tested it one by one
int ledPins1 [] = {6,7,8,9};
int ledPins2 [] = {10,11,12,13,};
int dam [] = {1,2,3,4,5};
int bridge [] = {1,2,3,4,5};
int pool [] = {1,2,3,4,5};
int waterfall [] = {1,2,3,4,5};
int jar1 = 1;
int jug1 = 22;
int jug2 = 23;
int UpWards = 4;
int DownWards = 5;
int Sun = 1;
void setup()
{
Serial.begin(9600);
pinMode(UpWards,INPUT_PULLUP);
pinMode(DownWards,INPUT_PULLUP);
pinMode(jug1,INPUT_PULLUP);
pinMode(jug2,INPUT_PULLUP);
pinMode(ledPins1, OUTPUT);
pinMode(ledPins2, OUTPUT);
}
void loop()
{
// CounterMain( &dam[0] ); // update dam[0]
// if(!digitalRead(jug1))
// {
// digitalWrite(ledPins1[dam[0]], HIGH);
// delay(100);
// digitalWrite(ledPins1[dam[0]], LOW);
// while(!digitalRead(jug1));
// }
CounterMain( &bridge[0] ); // update bridge[1]
if(!digitalRead(jug2))
{
digitalWrite(ledPins2[bridge[0]], HIGH);
delay(100);
digitalWrite(ledPins2[bridge[0]], LOW);
while(!digitalRead(jug2));
}
// CounterMain( &pool[0] ); // update pool[2]
// CounterMain( &waterfall[0] ); // update dam[3]
}
void CounterMain ( int * pX )
// void CounterMain ( int & val)
{
if(!digitalRead(4))
{
if( *pX < 10 )
{
(*pX)++;
}
delay(200);
}
if(!digitalRead(5))
{
if( *pX > 1 )
{
(*pX)--;
}
delay(200);
}
}
.
.
.
a lil. change I made here is putting zero everywhere
CounterMain( &dam[0] ); // update dam[0]
CounterMain( &bridge[0] ); // update bridge[0]
CounterMain( &pool[0] ); // update pool[0]
CounterMain( &waterfall[0] ); // update dam[0]