So I have 21 reed switches that I need to know when they are LOW to detect when a panel has been hit. I declared the pin # using an array. All of the switches need to be attached to an interrupt so I went through one by one and declared each attachInterrupt and created a corresponding function to that attachInterrrupt.
const int reedpins[] = {22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42}
pinMode(reedpins[1], INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(reedpins[1]), sensor1, FALLING);
void sensor1(){
Serial.write(63);
Serial.write(reedpins[1]);
}
The Serial.write(63) is just a number used to state incoming data from the arduino to the other arduino using Xbee communication.
My question is, if there is a way I can simplify this instead of copying and pasting the function 20 more times? Possibly using one function for all 21 sensors.
The switches are supposed to send their pin # so I know which switch was tripped and the receiving arduino will light an LED to display which switch was tripped. I thought about using the function to run through each sensor using a for loop and find which one is low but I only have a short amount of time for the pin is HIGH again (about 250ms), so I' am not sure if that will work effectively.