TobyOne:
attachInterrupt(digitalPinToInterrupt(encoderPin1), GetEncoderPulse(1), CHANGE);
obviously this doesn't work, just wondered why?
Because the declaration of attachInterrupt() is
void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)
The second argument is type "void (*)(void)" which means "a pointer to a function that takes no arguments and returns no value". If you try to pass the address of a function that takes a value, you will get a compile error:
void myISR(int arg) {}
void setup()
{
attachInterrupt(digitalPinToInterrupt(2), myISR, CHANGE);
}
void loop() {}
sketch_aug13a.ino: In function 'void setup()':
sketch_aug13a:5:58: error: invalid conversion from 'void (*)(int)' to 'void (*)()' [-fpermissive]
attachInterrupt(digitalPinToInterrupt(2), myISR, CHANGE);
^
It gets even worse when you try to specify an argument. Then you are not passing the address of (a.k.a. "a pointer to") a function; you are calling the function and passing the result of that call. Since the function returns 'void' you get an error for trying to use a void where a pointer is needed.
attachInterrupt(digitalPinToInterrupt(2), myISR(1), CHANGE);
sketch_aug13a.ino: In function 'void setup()':
sketch_aug13a:5:61: error: invalid use of void expression
attachInterrupt(digitalPinToInterrupt(2), myISR(1), CHANGE);
^
Note: You can trick attachInterrupt() into taking the pointer to you function by casting it to the correct type, but then there is no place to specify an argument and your function will get whatever garbage happens to be in the register or stack position used to pass the argument.
attachInterrupt(digitalPinToInterrupt(2), (void (*)()) myISR, CHANGE);