attachInterruptParam method

Posting it here because couldn't find any documentation on it. It is available for Arduino Nano Every, the signature is this:

void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback, PinStatus mode, void *param);

Callback signature in this case:

void callbackFunc(void *param);

Useful if you want to call static member function then you can pass your class instance as param, for example:

class MyClass
{
	int pin;
	volatile int count;
	
public:
	static void HandleInterrupt(void* param)
	{
		static_cast<MyClass*>(param)->count++;
	}
	MyClass(int pin): pin(pin), count(0)
	{
		attachInterruptParam(digitalPinToInterrupt(pin), &MyClass::HandleInterrupt, CHANGE, this);
	}
	int GetCount()
	{
		return count;
	}
};

MyClass test1(PIN2);
MyClass test2(PIN7);

void setup()
{
	Serial.begin(9600);
}
void loop()
{
	Serial.println(test1.GetCount());
	Serial.println(test2.GetCount());
}

See here:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.