Interrupts are great. But it's a bit difficult to use them in Arduino because the int numbers and pins don't line up. As a beginner, it was confusing to have to use "0" for pin 2 and "1" for pin 3. Why not add a line or two at the beginning of attachInterrupts and detachInterrupts to make the pins correspond? So then if you wanted a rising interrupt on pin2, you would do attachInterrupts(2, RISING, function); and attachInterrupts would decrement the number by 2. If we were using a mega's higher interrupts, then the formula is -pin + 23 (that's negative pin + 23)
So the complete listing:
pin int number how?
2 0 -2
3 1 -2
21 2 -pin + 23
20 3 -pin + 23
19 4 -pin + 23
18 5 -pin + 23
the only other modification needed would be to change the interrupt variable to an (signed) int to accommodate the intermediate negative numbers.
yes, exactly. Wouldn't that make it a tad easier for beginners to use interrupts? And isn't part of the idea of the Arduino project to create an easy-to-use board and language for beginners?
If people are so far that they can program interrupts they should be able to write a function like the one above. The interface of aattachInterrupt() is not too difficult so that extra layer is "costly".
Alternative could be to make some defines, which have the pinnummers in their name,
I just recently published a new higher performance Encoder library. Indeed, I had to put a bunch of definitions for the pin to int mapping on various boards. It's a shame that info isn't available as a macro or inline function from the core...