Okay, so I'm stuck at a quite small basic programming thingy.
So the situation:
I have 20 motion sensors connected to a (Controllino) mega board.
The 20 motion sensors are divided in 5 zones (arrays).
Example, zone 1:
int pir1 = CONTROLLINO_A0; //PIR 1
int pir2 = CONTROLLINO_A1; //PIR 2
int pir3 = CONTROLLINO_A2; //PIR 3
int pir4 = CONTROLLINO_A3; //PIR 4
int pir5 = CONTROLLINO_A4; //PIR 5
int pir6 = CONTROLLINO_A5; //PIR 6
int zone1[6] = {pir1, pir2, pir3, pir4, pir5, pir6};
The program have to be flexible to set up basic settings once on site. However this can also means the amount of sensors within a zone can change. or which pir# is in which zone.
Once a motion sensor is triggered, a function is called. I do this by checking each input every loop; if an input is HIGH, the function is called.
This all works fine and I'm really happy with it so far, but....
My issue:
Whenever I want to read which pir was responsible for activation, I have to manipulate what I pirNumber. In case of zone 1; + 1, in case of zone 2(which starts with pir7) I have to increment with 7.
for (int i = 0 ; i < amountZone1; i++) {
bool state = digitalRead(zone1[i]) ;
int pirNumber = i + 1; //here is my issue
}
I use the pirNumber to log as well as sending it further in the program.
This does make complete sense, since I read the index value.
So if I read zone1[0], I'll read the input number of the pir# which is at the first position of zone1[] array.
and I should read this as boolean to read if the input is HIGH or LOW.
So yes, I need that, I can not change the int-array to string array.
In the end, my question:
can I 'capture' the variable name from the array, without changing it to a String array or anything like that.
The main thing is that I have to be able to read whether the input is high or low, but it would be way nicer if I also can read which sensor was responsible for that.
Many thanks (again!)