Skip to content

Commit d044e05

Browse files
committed
DigitalPinToInterrupt docs added
The digitalPinToInterrupt is available in all architectures and was missing from the lang ref.
1 parent 9fd8d09 commit d044e05

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: digitalPinToInterrupt()
3+
categories: [ "Functions" ]
4+
subCategories: [ "External Interrupts" ]
5+
---
6+
7+
8+
9+
10+
11+
= digitalPinToInterrupt()
12+
13+
14+
// OVERVIEW SECTION STARTS
15+
[#overview]
16+
--
17+
18+
[float]
19+
=== Description
20+
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,3.
21+
22+
See link:../../external-interrupts/attachinterrupt[attachInterrupt()] for a full list of supported interrupt pins on all boards.
23+
24+
[%hardbreaks]
25+
26+
27+
[float]
28+
=== Syntax
29+
`digitalPinToInterrupt(pin)`
30+
31+
32+
[float]
33+
=== Parameters
34+
- `pin` - the pin we want to use for an interrupt.
35+
36+
37+
[float]
38+
=== Returns
39+
- The pin to interrupt (e.g. `2`)+
40+
- If pin is not available for interrupt, returns `-1`.
41+
42+
--
43+
// OVERVIEW SECTION ENDS
44+
45+
46+
47+
48+
// HOW TO USE SECTION STARTS
49+
[#howtouse]
50+
--
51+
52+
[float]
53+
=== Example Code
54+
// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄
55+
This example checks if a pin can be used as an interrupt.
56+
57+
[source,arduino]
58+
----
59+
int pin = 2;
60+
61+
void setup() {
62+
Serial.begin(9600);
63+
int checkPin = digitalPinToInterrupt(pin);
64+
65+
if (checkPin == -1) {
66+
Serial.println("Not a valid interrupt pin!");
67+
} else {
68+
Serial.println("Valid interrupt pin.");
69+
}
70+
}
71+
72+
void loop() {
73+
}
74+
----
75+
76+
--
77+
// HOW TO USE SECTION ENDS
78+
79+
80+
// SEE ALSO SECTION
81+
[#see_also]
82+
--
83+
84+
[float]
85+
=== See also
86+
87+
[role="language"]
88+
* #LANGUAGE# link:../../external-interrupts/attachinterrupt[attachInterrupts()]
89+
* #LANGUAGE# link:../../external-interrupts/detachinterrupt[detachInterrupts()]
90+
91+
--
92+
// SEE ALSO SECTION ENDS

0 commit comments

Comments
 (0)