# attachIntDio()

Enables DIO interrupts.

```cpp
void attachIntDio(uint8_t u8pin, E_PIN_INT_MODE mode)
```

For a preconfigured pin, the first parameter is the pin number for which you want to enable interrupts, the second is the interrupt direction ([rising, falling](broken://pages/-LwHw2ptOl3clGFYr-uD).

{% hint style="info" %}
Interrupt handlers and event handlers are written in [Application BEHAVIOR](/latest_en/api-reference/behavior.md).
{% endhint %}

## Example

Set up an interrupt to be generated when the DIO5 pin changes from HIGH to LOW.

```cpp
void setup() {
  the_twelite.app.use<myAppClass>();
  
  pinMode(PIN_DIGITAL::DIO5, PIN_MODE::INPUT_PULLUP);
  attachIntDio(PIN_DIGITAL::DIO5, PIN_INT_MODE::FALLING);
}

void loop() {
  ;
}
```

#### myAppClass.hpp

```cpp
class myAppClass: public mwx::BrdPal, MWX_APPDEFS_CRTP(myAppClasslMot)
{

};
```

Basic definition of the application behavior `myAppClass`. Details are omitted.

#### myAppClass.cpp

```cpp
/*****************************************************************/
// MUST DEFINE CLASS NAME HERE
#define __MWX_APP_CLASS_NAME myAppClass
#include "_mwx_cbs_cpphead.hpp"
/*****************************************************************/

MWX_DIO_INT(PIN_DIGITAL::DIO5, uint32_t arg, uint8_t& handled) {
  static uint8_t ct;
  digitalWrite(PIN_DIGITAL::DIO12, (++ct & 1) ? HIGH : LOW);
	handled = false; // if true, no further event.
}

MWX_DIO_EVENT(PIN_DIGITAL::DIO5, uint32_t arg) {
  Serial << '*';	
}

/*****************************************************************/
// common procedure (DO NOT REMOVE)
#include "_mwx_cbs_cpptail.cpp"
// MUST UNDEF CLASS NAME HERE
#undef __MWX_APP_CLASS_NAME
} // mwx
/*****************************************************************/
```

Description of the interrupt handler of the application behavior `myAppClass`, which inverts the output setting of DIO12 when an interrupt of DIO5 is generated and displays `*` on the serial port `Serial` for events occurring after the interrupt handler is finished.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mwx.twelite.info/latest_en/api-reference/funcs/dio/attachintdio.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
