The digitalPinToInterrupt() function takes a pin as an argument, and returns the same pin if it can be used as an interrupt. For example, digitalPinToInterrupt(4) on an Arduino UNO will not work, as interrupts are only supported on pins 2 and 3.
See attachInterrupt() for a full list of supported interrupt pins on all boards.
To verify if a given pin can be used an interrupt use the following function:
digitalPinToInterrupt(pin)
The function admits the following parameter:
pin: the pin we want to use for an interrupt.2).-1.This example checks if a pin can be used as an interrupt.
int pin = 2;
void setup() {
Serial.begin(9600);
int checkPin = digitalPinToInterrupt(pin);
if (checkPin == -1) {
Serial.println("Not a valid interrupt pin!");
} else {
Serial.println("Valid interrupt pin.");
}
}
void loop() {
}