Interrupts ISR function

Hello everybody :slight_smile: ,

I am trying to understand how to write this verbose code:

attachInterrupt(0, INT_Inputs0, CHANGE);
attachInterrupt(1, INT_Inputs1, CHANGE);
attachInterrupt(2, INT_Inputs1, CHANGE);
attachInterrupt(3, INT_Inputs2, CHANGE);
attachInterrupt(4, INT_Inputs3, CHANGE);
attachInterrupt(5, INT_Inputs4, CHANGE);
attachInterrupt(54, INT_Inputs54, CHANGE);

with a single function for each interrupt

into something like this:

for (int j = 0; j <= 54; j++){
 Ā  attachInterrupt(j, INT_Inputs(j), CHANGE);

with a single function that gets the variable ā€œjā€

How should I declare the variable inside the interrupt service routine inside the attachInterrupt function?


interrupts aren't invoked with any arguments. how does the hardware know what value to pass

in your case, the single interrupt would need to figure out which input changed.

what i've done is create separate interrupt service routines for each interrupt which then calls a common sub-function with an argument

First answer I can tell you....Don't use interrupts unless you really need them. They sound like a smart choose, and they aren't.

The valid questions about the wisdom of what you're trying to do notwithstanding, you would use an array of function pointers: Function Pointers in C and C++ -

Depending on which Arduino there might be alternative mechnisms for setting up an interrupt that
responds to changes on a range of pins.

Explaining what you are actually trying to achieve will be very useful - there is always a risk
this is an xyproblem.